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 |
HttpUtility.UrlEncode | Encoding+Test%3a+abc%c3%a4%c3%b6%c3%bc%c3%9f |
HttpUtility.UrlEncodeUnicode | Encoding+Test%3a+abc%u00e4%u00f6%u00fc%u00df |
HttpUtility.UrlPathEncode | Encoding%20Test:%20abc%c3%a4%c3%b6%c3%bc%c3%9f |
The single method HttpUtility.UrlDecode() decodes all encoded query strings.
On the client side there are JavaScript functions to encode and decode query strings, namely escape() and 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 encodeURIComponent() and 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.
By the way, I recommend having a look at QuickRef.org, I really like their fast Ajax-enabled search engine for references of C, C++, CSS, HTML, HTML DOM, Java, JavaScript, MySQL, Perl, PHP and Ruby.
Now playing: New Order - Get ready - Vicious streak