Unicode URL character encoding

How to encode URLs containing Unicode? I would like to pass it to the command line utility, and I need to encode it first.

Example: http://zh.wikipedia.org/wiki/白雜訊

becomes http://zh.wikipedia.org/wiki/%E7%99%BD%E9%9B%9C%E8%A8%8A.

+5
source share
4 answers

You can use the method HttpUtility.UrlPathEncodein the assembly System.Web(requires the full .NET Framework 4 profile):

var encoded = HttpUtility.UrlPathEncode("http://zh.wikipedia.org/wiki/白雜訊");
+7
source

According to MSDN, you can no longer use UrlPathEncode.

So, the right way to do it now,

var urlString = Uri.EscapeUriString("http://zh.wikipedia.org/wiki/白雜訊");
+4
source
Server.UrlEncode(s);

.NET strings are Unicode strings (UTF-8 encoding, to be specific), so you only need to call HttpServerUtility.UrlEncode (although the so-called "internal" server property will be available in most contexts in asp.net, where you can do it).

0
source

I had a problem with the Turkish character. <a href="/@Html.Raw(string)"solved a problem

0
source

All Articles