Whenever you append a query string to an URL, it's a best practice to URL-encode the query string value. On the server side encoding can be done by three methods of the
System.Web.HttpUtility class, depending on the desired output.
Here's an example passing "Encoding Test: abcäöüß" to the methods:
|Method ||Output |
The single method
HttpUtility.UrlDecode() decodes all encoded query strings.
unescape(). However, these functions have problems with the correct encoding of UTF-8 strings.
Today I had the same problem described in the article above while debugging search in dasBlog, which uses UTF-8 as the default request and response encoding. You can enable UTF-8 for any ASP.NET web site by including the following element in your web.config.
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
All search queries containing umlauts were retrieved without umlauts on the server side, so a query for König would result in Knig. The solution was to leverage the newer encoding functions
decodeURIComponent() respectively which handle Unicode.
If you're interested in encoding in general I recommend Scott Hanselman's excellent podcast on globalization and internationalization. It gives a good overview without diving too deep into the details.