【发布时间】:2012-02-09 00:03:12
【问题描述】:
我正在尝试为 URI 类启用 IDN/IRI 支持,因为我需要德语变音符号域(例如 www.bücher.de)上的“Uri.IsWellFormedUriString”方法。
我在https://stackoverflow.com/a/6107682/413531 发现了类似的问题(取自“国际资源标识符支持”的http://msdn.microsoft.com/en-us/library/system.uri.aspx),但该解决方案对我不起作用。我当前的 app.config 文件如下所示:
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="..." type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<!-- ... some sections in here ... -->
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<!-- ... some sections in here ... -->
</sectionGroup>
</configSections>
<userSettings>
<!-- ... some settings in here ... -->
</userSettings>
<applicationSettings>
<!-- ... some settings in here ... -->
</applicationSettings>
</configuration>
当我刚刚添加时
<uri>
<idn enabled="All" />
<iriParsing enabled="true" />
</uri>
作为最后的另一个孩子,抛出异常:ConfigurationErrorsException - {"Das Konfigurationssystem konnte nicht initialisiert werden."}
所以我在http://msdn.microsoft.com/en-us/library/system.uri.aspx 中阅读了更多内容
Uri 类中的 IRI 和 IDN 处理也可以通过使用来控制 System.Configuration.IriParsingElement, System.Configuration.IdnElement 和 System.Configuration.UriSection 配置设置类。这 System.Configuration.IriParsingElement 设置启用或禁用 IRI 在 Uri 类中处理。 System.Configuration.IdnElement 设置启用或禁用 Uri 类中的 IDN 处理。这 System.Configuration.IriParsingElement 设置也间接 控制 IDN。必须启用 IRI 处理才能进行 IDN 处理 可能的。如果禁用 IRI 处理,则 IDN 处理将 设置为 .NET Framework 2.0 行为所在的默认设置 用于兼容性和不使用 IDN 名称。
不幸的是,我找不到 System.Configuration.IriParsingElement、System.Configuration.IdnElement 和 System.Configuration.UriSection 的使用示例。我不知道这些是如何使用的......
所以基本上,我的问题归结为:我想在 URI 类中启用 IDN/IRI 支持,但我不知道该怎么做。配置解决方案对我不起作用,所以我想通过代码尝试,但不知道如何。顺便提一句。我也想知道为什么配置不工作;)
【问题讨论】: