3

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:

  1. Get domain part
  2. If there are any Unicode symbols, process domain part using IdnMapping().GetAscii
  3. Process query part using Uri.EscapeUriString()

Partially related question how-to-convert-idn-to-ascii

Community
  • 1
  • 1
Mekanik
  • 2,532
  • 1
  • 22
  • 20

0 Answers0