在Web应用程序中禁用Dns缓存/关闭打开连接
问题描述:
我目前正在使用ASP.NET Web应用程序(基本VS2017 MVC模板),并且由于需要在两个应用程序之间切换,我需要完全禁用DNS缓存浏览器端,并关闭任何开放的连接。目前,即使DNS记录更改后,Chrome和IE仍然会路由到应该死的页面。在Web应用程序中禁用Dns缓存/关闭打开连接
帖子我已经试过:
-
How to add .htaccess file to my Visual Studio solutions具有低
cacheControlMaxAge
,然后使用cacheControlMode="DisableCache"
- How to control web page caching, across all browsers?我用ASP.NET建议。
- How can I disable HTTP Keep-Alive in ASP.NET MVC?
对于最后一个,我不知道我有工作按预期。将上述每个我的头后有:
响应头:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Content-Length: 1079
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: 0
Vary: Accept-Encoding
Server: Microsoft-IIS/8.0
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 02 Aug 2017 21:36:50 GMT
请求报头:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:ARRAffinity=789fe7bbe28c722b0920137dba18498fceae0426a05f2d26c581fb12b875c8d9
Host:[redacted]
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
keep-alive
似乎依然为请求启用,但我不知道如果这有什么影响。
由于VS中的默认设置,我也有两个Web.config文件。我一直在做我的变化,看看有什么关系。下面是编辑的部分:
的意见/ Web.config中:
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
<httpProtocol allowKeepAlive="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
APPNAME/Web.config中
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
<httpProtocol allowKeepAlive="false" />
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
我最好的猜测是,我的浏览器不重新检查DNS记录,因为使用nplookup检查它即使在旧页面仍然运行时也会提供重定向的位置。使用Wireshark查看网络流量显示连接保持打开状态,所以这可能是原因。任何关于如何强制浏览器重新检查DNS记录的建议将不胜感激。先谢谢你。
答
原来问题确实是“keep-alive”标题。更具体地说,是由于任何Dns查找而导致的开放连接。访问IIS管理器并将HTTP响应头更改为禁用保持活动状态会强制浏览器每次都重新检查Dns记录。
你确定你了解DNS是什么,为什么浏览器中没有DNS缓存,为什么你无法通过网站响应来控制它? –
https://superuser.com/questions/203674/how-to-clear-flush-the-dns-cache-in-google-chrome我接受其他想法,但这是我最好的猜测,因为我为什么' m不断地重定向到错误的站点。 – dornadigital
好吧,谷歌重新发明了轮子,并创建了另一个DNS缓存,但仍然无法通过网站响应来控制它,因为DNS实际上需要_before_实际上请求您的网站 –