简体   繁体   English

IIS缓存HttpContext.Current.Request.Url.Authority

[英]HttpContext.Current.Request.Url.Authority is getting cached by IIS

I have a web application (asp.net, C#) running for more than 2 months for internal employees of my company. 我的公司内部员工有一个运行了两个月以上的Web应用程序(asp.net,C#)。 The application was accessible by live IP address like 121.XXX.XX.200. 可通过实时IP地址(例如121.XXX.XX.200)访问该应用程序。

In my code-base, I used "HttpContext.Current.Request.Url.Authority" to get this particular IP address. 在我的代码库中,我使用“ HttpContext.Current.Request.Url.Authority”来获取此特定IP地址。 This was also working fine till day before yesterday. 直到前一天,它也可以正常工作。

However, yesterday the code "HttpContext.Current.Request.Url.Authority" started giving me local IP address of the server like "10.X.XXX.20" instead of the live one. 但是,昨天代码“ HttpContext.Current.Request.Url.Authority”开始为我提供服务器的本地IP地址,如“ 10.X.XXX.20”,而不是实时的IP地址。

Now I was able to reproduce the error. 现在,我能够重现该错误。 Whenever I browse the application using the local IP address, IIS seems to be caching the domain name. 每当我使用本地IP地址浏览应用程序时,IIS似乎都在缓存域名。 Now when I browse the same application using live IP address from different computer. 现在,当我使用来自另一台计算机的实时IP地址浏览同一应用程序时。 It still gives me the local IP. 它仍然给我本地IP。

What can be the solution to this? 有什么解决方案?

Try using HttpContext.Current.Request.Url.Host instead of HttpContext.Current.Request.Url.Authority . 尝试使用HttpContext.Current.Request.Url.Host而不是HttpContext.Current.Request.Url.Authority

As long as I remember Authority gets the DNS domain name of host which can cause problems sometimes. 只要我记得Authority会获得主机的DNS域名,这有时可能会引起问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM