间歇性“无法解析远程名称”?

发布于 2024-10-31 13:22:22 字数 226 浏览 3 评论 0原文

我有一个 ASP.NET 应用程序,经常用它通过 HttpWebRequest 读取网页的内容。远程地址没有问题,我的应用程序始终工作正常。

虽然我没有更改任何内容,但有时(大约每天一次)我会收到此错误:

the remote name could not be resolved.

为什么以前解析的 DNS 名称有时无法解析?

I have an ASP.NET application that I use to read the contents of a web page by a HttpWebRequest frequently. There's no problem with the remote address and my application is always working fine.

While I don't change anything, sometimes (about once a day) I get this error:

the remote name could not be resolved.

Why a previously resolved DNS name sometimes fails to be resolved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

命硬 2024-11-07 13:22:22

这种间歇性的问题将非常难以解决,需要更改配置而不是代码解决方案。 (提示:阅读所有内容;)

我猜测远程服务器 DNS 经常会过期。可能每天一次,甚至可能每 12 小时左右一次。这是 TTL(生存时间)设置。如果管理员需要能够快速将站点移动到新服务器,他们有时会人为地将其设置为较低的级别。

您可以通过转到命令提示符并运行来确定它过期的频率:

nslookup
set debug
www.theserverdomain.com

在该命令的顶部将有一个部分显示“AUTHORITY RECORDS:”,其下有一个项目显示“ttl”。

现在,(我在这里做出一个有根据的猜测),当您查询 DNS 服务器来解析您的服务器将缓存此值的主机名时,可能会发生什么。

然而,一旦过期,您的服务器将不得不联系上游的另一台服务器来获取 IP 地址解析,称为 DNS 转发。如果您的服务器和远程服务器之间有很多跃点,或者站点之间的其中一台 DNS 服务器过载,那么它可能会超时并发回您收到的消息。

如果这是真的,那么您唯一能做的就是将 DNS 和 IP 地址组合硬编码到您的 Web 服务器主机文件中。这通常位于C:\Windows\System32\drivers\etc,是一个名为“hosts”的文件。有一个关于如何在文件本身中正确编辑此内容的示例。

在该文件中创建主机映射后,您的 Web 服务器将不再需要联系 DNS 服务器来执行名称解析,并且 TTL 设置为多少也无关紧要。

这里唯一的危险是他们将网站移至新的 IP 地址。此时您只需再次更新您的主机文件即可...

The intermittent nature of this is going to be extremely difficult to resolve and it's going to take a configuration change instead of a code solution. (hint: read everything ;)

I would guess that the remote servers DNS is set to expire pretty often. Probably daily or maybe even every 12 hours or so. This is the TTL (time to live) setting. Admins sometimes set this to an artificially low level if they need the ability to quickly move the site to a new server.

You can determine how often it expires by going to a command prompt and running:

nslookup
set debug
www.theserverdomain.com

At the top of this will be a section that says "AUTHORITY RECORDS:" with an item under it that says "ttl".

Now, (and I'm making an educated guess here), what's probably happening when you query your DNS server to resolve that host name your server will have this value cached.

However, once it expires the your server will have to contact another server upstream to get the ip address resolution, called DNS forwarding. If there are a lot of hops between yours and the remote server OR if one of the DNS servers between the sites is overloaded then it could timeout and send back the message you are receiving.

If this is true then the ONLY thing you can do is hardcode the DNS and IP address combination in your web servers hosts file. This is usually at C:\Windows\System32\drivers\etc and is a file named "hosts". There is an example on how to properly edit this within the file itself.

Once you create the host mapping in that file, your web server will no longer have to contact the DNS server to perform name resolution and it won't matter what the TTL is set to.

The only danger here is if they move the web site to a new IP address. At which point you could simply update your hosts file again...

怪我入戏太深 2024-11-07 13:22:22

我要检查的第一件事是 DNS 是否不再正确配置或出现故障。

尝试(从 Windows 命令行)

nslookup MyDnsNameHere

并查看是否获得您期望的 IP。

The first thing I would check is if DNS is no longer correctly configured or malfunctioning.

Try (from a Windows command line)

nslookup MyDnsNameHere

and see if you get the IP you would expect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文