忽略主机文件?

发布于 2024-09-10 10:37:51 字数 285 浏览 10 评论 0原文

我需要从 C# 调用 Response.Redirect 方法,但我需要以这样的方式执行此操作:它会忽略 Windows 上的此调用的 Hosts 文件?

例如,如果在主机上我有:

127.0.0.1 google.com

并且我调用 Response.Redirect("google.com"),我需要它忽略仅针对这一调用的主机,而实际上转到 google.com比本地主机。我怎么能这样做呢?

我知道我可以在谷歌的IP地址上调用Response.Redirect,但是有更好的方法吗?

I need to call a Response.Redirect method from C# but I need to do it in such a way that it ignores the Hosts file on windows for this call?

For example, if on Hosts I have:

127.0.0.1 google.com

and I call a Response.Redirect("google.com"), I need it to ignore the hosts just for this one call and actually go to google.com rather than localhost. How could I do this?

I know I could call a Response.Redirect on google's IP address but is there a better way?

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

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

发布评论

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

评论(3

溺渁∝ 2024-09-17 10:37:51

不,可能不会:DNS 查找将移交给您的操作系统,该操作系统会检查...hosts 文件。

如果您可以

  • 在没有操作系统解析器的情况下查找 IP 地址,
  • 并且目标服务器接受 IP 地址而不是主机名(某些网络服务器将拒绝提供 http://10.15.6.4/some/path (Google 搜索接受 IP 主机名并且可以工作,顺便说一句)),

那么它可能会工作。

No, probably not: DNS lookup is handed over to your OS, which checks...hosts file.

Iff you can

  • look up the IP address without the OS's resolver
  • and the target server accepts IP address instead of hostname (some webservers will refuse to serve http://10.15.6.4/some/path (Google Search accepts an IP hostname and works, btw)),

then it might work.

不必在意 2024-09-17 10:37:51

忽略主机文件的唯一方法是将其删除。

The only way to ignore the hosts file is to delete it.

梦途 2024-09-17 10:37:51

如果您无需询问操作系统(例如通过第 3 方)即可知道主机的 IP 地址。那么您实际上忽略了主机文件。

If you can know the IP address of the host without asking the OS ( e.g. via 3rd party ) .. then you actually ignored the hosts files .

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