Context: ASP.NET MVC running in IIS with a UTF-8% URL.
Using the standard project template and test action in HomeController , for example:
public ActionResult Test(string id) { return Content(id, "text/plain"); }
This is great for most%-coded UTF-8 routes, such as:
http://mydevserver/Home/Test/%e4%ba%ac%e9%83%bd%e5%bc%81
with expected result 京都 弁
However, using the route:
http://mydevserver/Home/Test/%ee%93%bb
URL received incorrectly.
In addition: %ee%93%bb is a% -coded code point 0xE4FB; basic multilingual aircraft; private sector; but ultimately the actual Unicode code point; You can check this manually or via:
string value = ((char) 0xE4FB).ToString(); string encoded = HttpUtility.UrlEncode(value);
Now what comes next depends on the web server; the correct id received on the Visual Studio development server (aka cassini) - a line of length one containing the code point 0xE4FB.
If, however, I do this in IIS or IIS Express, I get another id , in particular "î"»" , code points: 0xEE, 0x201C, 0xBB. You will immediately recognize the first and last as the beginning and end of our percentage encoded string ... so what happened in the middle?
Well:
I really like that when I processed my URL, IIS did some kind of quotation translation. Now, perhaps this can be used in several scenarios (I don’t know), but it is, of course, bad when it happens in the middle of a block encoded with% -encoded UTF-8.
Please note that HttpContext.Current.Request.Raw also indicates that this translation has occurred, so this does not look like an MVC error; also note Darin’s comment, emphasizing that it works differently in the path to the URL request part.
So (two-part):
- Is there any important subtlety of handling unicode / url in my analysis?
- How can i fix this? (i.e. make sure I get the expected character)