I have an Url, for example, http://кц.рф/ru/registrators/
and want to convert it to http://xn--j1ay.xn--p1ai/ru/registrators/
form.
new System.Globalization.IdnMapping().GetAscii(href)
// result: xn--http://-jig2i.xn--/ru/registrators/-zdo8d
System.Web.HttpUtility.UrlPathEncode(href)
// result: http://%d0%ba%d1%86.%d1%80%d1%84/ru/registrators/
More general problem is to normalize urls like: http://кц.рф/ru/registrators/q?рф=세요
Is there a simpler way to do this rather than:
- Get domain part
- If there are any Unicode symbols, process domain part using
IdnMapping().GetAscii
- Process query part using
Uri.EscapeUriString()
Partially related question how-to-convert-idn-to-ascii