ASP.Net: HTTP 400 Bad Request error when trying to process http://localhost:5957/http://yahoo.com

后端 未结 12 2401
小鲜肉
小鲜肉 2020-12-21 02:04

I\'m trying to create something similar to the diggbar.

I\'m using Visual Studio 2010 and Asp Development server.

However, I can\'t get the ASP dev server

相关标签:
12条回答
  • 2020-12-21 02:55

    From Stefan on the ASP.Net team: http://forums.asp.net/p/1431148/3221542.aspx

    In current versions of ASP.NET Urls containing characters like the colon character will be rejected as a potential security threat. The historical reason for this is that the underlying NTFS file system supports alternate resource streams that can be accessed with names like "yourfile.txt:hiddendata.txt". Blocking the colon character from Urls prevents poorly written applications from accidentally working with alternate resource streams.

    There is also a limitation in current versions of ASP.NET that incoming Urls need to map to the NTFS file system for purposes of determining managed configuration data.

    In ASP.NET 4 these limitations can be optionally removed. However these changes are in the Beta 2 version of ASP.NET 4 - they are not in Beta 1. We tried out the Url listed earlier in this forum post and confirmed that with our internal builds of ASP.NET 4 you can use that style of Url and process it without any 400 error.

    -Stefan

    0 讨论(0)
  • 2020-12-21 02:55

    A quick solution for development environment:

    • Change Web project properties to "Use IIS Local Server" and check "Use IIS Express" (which preserves the URL of VS Dev Server).

    • Add the following setting in Web.config inside <system.web>:

      <httpRuntime requestPathInvalidCharacters="" />
      

    For production deployment, take into account the security considerations mentioned in other answers.

    0 讨论(0)
  • 2020-12-21 02:56

    Try HttpUtility.UrlPathEncode(url) - MSDN Docs

    0 讨论(0)
  • 2020-12-21 02:58

    I'm not sure what web server digg is using but I'm betting this simply isn't possible with IIS or the built in web server for VS. Most likely it's a web server that can be modified to allow all sorts of wacky URLs.

    0 讨论(0)
  • 2020-12-21 02:59

    I answered a similar question here.

    https://stackoverflow.com/a/12037000/134761

    Basically, ASP.net only accepts encoded characters such as colon after the question mark. Fortunately ASP.net MVC automatically maps both /api/persons/xxxx and /api/persons?id=xxxx equally in the default mapping, so that is what I ended up doing.

    0 讨论(0)
  • 2020-12-21 03:07

    You need to use HttpUtility.UrlEncode on your string before redirecting to it.

    0 讨论(0)
提交回复
热议问题