This is not a new queestion
There are quite a few of questions here on SO about IE having some problems with handling special characters in the querystrings. In all of the cases it is the same: Chrome, Firefox, Safari (everyone) handles the UTF-8 encoded URLs correctly, almost all of them even handles the cases where the IRIs aren't encoded into URLs. But IE insists on make life hard for the developers.
As I have run into the problem myself, and have worked quite a bit with it. To me it seems that IE for some reason insists on decoding the UTF-8 encoded URL into ISO-8859-1 before sending it to the server.
My case
I am a resident in Denmark, and therefor I have to work with the danish letters æøå. There a many cases where I want to send parameters from my views into some C# methods. Two examples of such places where the special characters often pop up:
Say a Dane wants to search for the danish word "æblegrød" (special kind of apple pie). In Chrome and Firefox, if I just feed the browser with the IRI:
http://example.com/Search/QuickSearch?searchQuery=æblegrød
The query sent to the server would look like this:
http://example.com/Search/QuickSearch?searchQuery=%C3%A6blegr%C3%B8d
In Internet Explorer however it would look like this:
http://example.com/Search/QuickSearch?searchQuery=æblegrød
It is now easy to see what the problem is. Firefox & Chrome are URL encoding the URLs
... each byte that is not an ASCII letter or digit to %HH, where HH is the hexadecimal value of the byte
http://www.w3.org/International/O-URL-code.html
Where Internet Exlorer instead is doing a direct UTF-8 encoding of the string, resulting in "æblegrød". This is also the same end results as if you take a UTF-8 string and decode it as if it was ISO-8859-1, is this a coincidence?
I have tried some things
As Internet Explorer has the option to "send URL path as UTF-8" I tried disabling that. Changing nothing.
As it went wrong when IE has to handle "searchQuery=æblegrød" I tried encoding the IRI before handing it to the browser. Resulting in all browsers getting the following URL to work with:
http://example.com/Search/QuickSearch?searchQuery=%C3%A6blegr%C3%B8d
IE however doesn't care, what I see in the networking log is still the URL
http://example.com/Search/QuickSearch?searchQuery=æblegrød
being sent to the server.
This is how my configuration is:
I set the meta tag:
<meta charset="UTF-8">
IE sends URL-paths as UTF-8 (also set IE to do this for intranet querystrings)
Globalization set to UTF-8
<globalization
uiCulture="da-DK"
culture="da-Dk"
fileEncoding="utf-8"
responseEncoding="utf-8"
requestEncoding="utf-8"
responseHeaderEncoding="utf-8" />
I am running out of ideas, I don't know what it is that I am doing wrong. I am leaning towards IE creating the havoc, but I genuinely do not know if it is something that I have set up wrongly in my project.
These characters are "{", "}", "|", "\", "^", "~", "[", "]", and "`". All unsafe characters must always be encoded within a URL.
Special characters, including the following are not acceptable: (){}[]|`¬¦! "£$%^&*"<>:;#~_-+=,@. If you do use a disallowed character and the system does not recognize your mistake you will not be allowed to use the password or username to log into your account later.
An answer to the future people hitting this question.
Playing around with this, I got to the conclusion that the only thing I could do was to encode all of my URL's, and then work with the Content Disposition (with help from this SO post) to make it work for different browsers. The solution is not perfect, it still has some flaws, but it is the best approach I have found so far.
In all of my cases, the links were build with JS, so encodeURIComponent is my go-to method to encode the URLs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With