-4

Web.HttpUtility.UrlEncode method in my project. When I am encoding name in English language then I got correct result. For example,

string temp = System.Web.HttpUtility.UrlEncode("Jewelry");

then I got exact result in temp variable. But if I wrote name in Russian language then I got different result.

string temp = System.Web.HttpUtility.UrlEncode("ювелирные изделия"); 

then I got value in temp variable like "%d1%8e%d0%b2%d0%b5%d0%bb%d0%b8%d1%80%d0%bd%d1%8b%d0%b5+%d0%b8%d0%b7%d0%b4%d0%b5%d0%bb%d0%b8%d1%8f"

Can anyone help me how to achieve exact name as per language?

Thank you!

Ankita
  • 1,416
  • 4
  • 17
  • 42

2 Answers2

0

Actually, the method has "done the right thing" for you!

It encodes non-ASCII characters so that it can be valid in all of the cases and transmit over the Internet. If you put your temp variable in an URL as a parameter, you will get your correct result at server side. That's what UrlEncode means for. Here your question is not a problem at all. So please have a look at this link for further reading to understand about URL Encoding: http://www.w3schools.com/tags/ref_urlencode.asp

If you input that Russian word to the "URL Encoding Functions" part in the page I have given, it will return the same result as Web.HttpUtility.UrlEncode method does.

Envil
  • 2,687
  • 1
  • 30
  • 42
0

Can anyone help me how to achieve exact name as per language?

In short: not with that method, but it might depend on what is your exact goal.

In details:

In general URIs as defined by RFC 3986 (see Section 2: Characters) may contain any of the following characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=. Any other character needs to be encoded with the percent-encoding (%hh).

This is why UrlEncode produces

UrlEncode("Jewelry") -> "Jewelry"
UrlEncode("ювелирные изделия") -> "%d1%8e%d0%b2%d0%b5%d0%bb%d0%b8%d1%80%d0%bd%d1%8b%d0%b5+%d0%b8%d0%b7%d0%b4%d0%b5%d0%bb%d0%b8%d1%8f"

The string of "ювелирные изделия" contains characters that are not allowed in a URL as per RFC 3986.

Today, modern browsers could work with UTF-8 in URL it might be not necessary to use UrlEncode(). See example: http://jsfiddle.net/ybgt96ms/

Community
  • 1
  • 1
user2316116
  • 6,726
  • 1
  • 21
  • 35