Getting error 400 / 404 - HttpUtility.UrlEncode not encoding full string?

Posted by Justin808 on Stack Overflow See other posts from Stack Overflow or by Justin808
Published on 2011-01-05T00:55:09Z Indexed on 2011/01/05 1:54 UTC
Read the original article Hit count: 291

Filed under:
|
|

Why do the following URLs give me the IIS errors below:

A) http://192.168.1.96/cms/View.aspx/Show/Small+test'

A2) http://192.168.1.96/cms/View.aspx/Show/Small%20test' <-- this works, but is not the result from HttpUtility.UrlEncode()

B) http://192.168.1.96/cms/View.aspx/Show/'%26$%23funky**!!~''+page

Error for A:

HTTP Error 404.11 - Not Found
The request filtering module is configured to deny a request that contains a double escape sequence.

Error for B:

HTTP Error 400.0 - Bad Request
ASP.NET detected invalid characters in the URL.

The last part of the URL after /Show/ is the result after the text is being sent through HttpUtility.UrlEncode() so, according to Microsoft it is URL Encoded correctly.

If I user HttpUtility.UrlPathEncode() rather than HttpUtility.UrlEncode() I get the A2 results. But B ends up looking like:

http://192.168.1.96/TVCMS-CVJZ/cms/View.aspx/Show/'&$#funky**!!~''%20page

which is still wrong. Does Microsoft know how to URL Encode at all? Is there a function someone has written up to do it the correct way?

© Stack Overflow or respective owner

Related posts about c#

Related posts about iis6