我有一小段代码,如下所示:
private string ResolveAddress(string domain)
{
try
{
if (Regex.IsMatch(domain, @"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}"))
return domain;
else
return Dns.GetHostAddresses(domain)[0].ToString();
}
catch (Exception ex)
{
Error.Record("Exception caught in ResolveAddress", ex);
return domain;
}
}
今天,我第一次有人抱怨他们无法连接到我的主机。我查看他们的日志并看到以下异常:
# 6/20/2013 9:28:59 AM: Exception caught in ResolveAddress
Exception message: Configuration system failed to initialize
Exception stack trace: at System.Configuration.ConfigurationManager.PrepareConfigSystem()
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.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at NDTPresence.MainWindow.ResolveAddress(String domain)
显然,如果Dns.GetHostAddresses
呼叫失败,他们将无法连接到我的服务。我的问题是为什么会发生这种情况?如果在用户的 AppData/Roaming 中出现此主机名的配置文件,但他们为每个人都安装了它(我相信)。
谢谢。