IdnMapping.GetAscii method in .NET C# not working as expected

675 Views Asked by At

When I call IdnMapping.GetAscii(http://президент.рф/) I am getting result xn--http://-5ggibum1ewap2b.xn--/-4tbm which is not correct.

I don't know where is the problem ? Is this method works as expected in C# ? When I copy paste same url in Google Chrome which auto converts this into http://xn--d1abbgf6aiiy.xn--p1ai/

1

There are 1 best solutions below

1
On BEST ANSWER

Domain names do not include the protocol prefix. Remove http:// and the trailing backslash to get the exact same result.

    static void Main(string[] args) {
        var map = new System.Globalization.IdnMapping();
        Console.WriteLine(map.GetAscii("президент.рф"));
    }

Output:

xn--d1abbgf6aiiy.xn--p1ai