locked
Converting domain names from russian to universal

    Question

  • Hi!

    I need to convert russian domain to universal form. For example президент.рф into XN--D1ABBGF6AIIY.XN--P1A. How I can do it (desirable in .NET)?

    Problem is that class HttpWebRequest doesn't "uderstand" russian domains, it fails when it do request. If there is a possibility to "tеach" HttpWebRequest to "understand" russian domain - it is another solution.

    Thanks.

    Wednesday, January 12, 2011 11:37 AM

Answers

  • It's simple not supported by .Net lower than 4.0. I create new windows forms application, compile it for .net 4.0 - work, .net 4.0 client profile - work, .net 3.5 - fails, .net 3.5 client profile - fails. Service was compiled for 3.5 - and fails.

    But in MSDN written article for 3.5 framework too (http://msdn.microsoft.com/en-us/library/bb882619%28v=VS.90%29.aspx). Strange...

     

    • Marked as answer by nnm2005 Friday, January 14, 2011 11:39 AM
    Friday, January 14, 2011 11:36 AM

All replies

  • That is called punycode and you will find some information about it on Wikipedia and StackOverflow

     

    Wednesday, January 12, 2011 2:47 PM
  • There is apparently support in the Uri class, but might need enabling...  See http://msdn.microsoft.com/en-us/library/system.uri.aspx  SO maybe it'll just work -- HttpWebRequest just seeing a Uri...

    Haven't tried myself. :-)


    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
    Thursday, January 13, 2011 10:33 AM
  • Alan, Eugene, thanks for reply. I see in this article http://msdn.microsoft.com/en-us/library/system.uri.aspx that it is possible to write app config like this:

    <configuration>
    ...<br/>
     <uri>
     <idn enabled="All" />
     <iriParsing enabled="true" />
     </uri>
    </configuration>
    
    

    But application fails:

    System.TypeInitializationException: The type initializer for 'log4net.GlobalContext' threw an exception. ---> 
    System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> 
    System.Configuration.ConfigurationErrorsException: Unrecognized configuration section uri. 
    (d:\projects\Source\trunk\service\bin\Debug\service.exe.Config line 17)
      at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
      at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
      at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
      --- End of inner exception stack trace ---
      at System.Configuration.ConfigurationManager.GetSection(String sectionName)
      at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
      at System.Net.Configuration.SettingsSectionInternal.get_Section()
      at System.Net.Sockets.Socket.InitializeSockets()
      at System.Net.Dns.GetHostName()
      at log4net.Util.SystemInfo.get_HostName()
      at log4net.GlobalContext..cctor()
    How to fix this?

    Thursday, January 13, 2011 1:43 PM
  • Your .config file isn't well-formed; looks like you've for the "uri" section inside a log4net section... (But I don't know much about log4net)

    The output from my test show the following.  Note the DnsSafeHost value "xn--d1abbgf6aiiy.xn--p1ai".  This just contains the Unicode string when the .config file is missing.

    ---------------------------
    http://президент.рф/
    --------------------------
    AbsolutePath: 
    AbsoluteUri: http://президент.рф/
    Authority: президент.рф
    Host: президент.рф
    HostNameType: Dns
    IsDefaultPort: True
    IsFile: False
    IsLoopback: False
    IsUnc: False
    LocalPath: /
    PathAndQuery: /
    Port: 80
    Query: 
    Fragment: 
    Scheme: http
    OriginalString: http://президент.рф
    DnsSafeHost: xn--d1abbgf6aiiy.xn--p1ai
    IsAbsoluteUri: True
    Segments: System.String[]
    UserEscaped: False
    UserInfo: 
    

    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
    Thursday, January 13, 2011 7:13 PM
  • No, it's not log4net section, we use for log4net another .config file. In app.config for service there isn't log4net section. And <uri> element is nested into <configuration> element. I think that it's not log4net problem, it log4net message from log4net log file.

    May be it must be nested into another element, not <configuration>? I will experiment with this later.

    Or may be you have working app.config file with <uri> section?

    Friday, January 14, 2011 10:58 AM
  • It's simple not supported by .Net lower than 4.0. I create new windows forms application, compile it for .net 4.0 - work, .net 4.0 client profile - work, .net 3.5 - fails, .net 3.5 client profile - fails. Service was compiled for 3.5 - and fails.

    But in MSDN written article for 3.5 framework too (http://msdn.microsoft.com/en-us/library/bb882619%28v=VS.90%29.aspx). Strange...

     

    • Marked as answer by nnm2005 Friday, January 14, 2011 11:39 AM
    Friday, January 14, 2011 11:36 AM
  • It is supported but you have to add following to your app.config file in .NET 3.5.

    <configSections>
      <section name="uri" type="System.Configuration.UriSection, System,
                              Version=2.0.0.0, Culture=neutral,
                              PublicKeyToken=b77a5c561934e089" />
    </configSections> 

    Thursday, December 15, 2011 9:51 AM