jump to navigation

ASP.NET detected invalid characters in the URL (HTTP Error 400.0 – Bad Request) April 8, 2009

Posted by kevinbe71 in ASP.NET, Development, MVC, Web Development.
trackback

I ran into this error when writing a web app using ASP.NET MVC and using a comma in one of the input params used in the URL.  IIS 7 reported the error in the following way:

In “Error Summary” it had “HTTP Error 400.0 – Bad Request” and “ASP.NET detected invalid characters in the URL.”

In “Detailed Error Information” the Request URL was something like this and hovering over the link showed the same URL:
http://localhost/BaseUrl/Some_Path%2c_And_More/View

In the browser’s address box the URL was displayed as:
http://localhost/BaseUrl/Some_Path%252c_And_More/View

The comma was being double-encoded (%2c –> %252c) !  I didn’t spot the difference at first until I used the W3 Schools reference on URL encoding (http://www.w3schools.com/TAGS/ref_urlencode.asp) and noticed the encoding of %.

So, in the end the solution was to remove the bit of code that was doing the extra URL encoding.  Pretty simple really…

Comments»

No comments yet — be the first.