IIS7.5 OutputCacheModule 内核缓存“公共”忽略网址

发布于 2024-10-11 14:28:38 字数 1057 浏览 4 评论 0 原文

IIS 7.5 上的 ASP.NET 4 应用程序中的输出缓存存在一些奇怪的行为。我已经能够在其他空设置上重复这个问题,我确定这是一个错误,但不确定如何将其报告给 Microsoft。

IIS 中的站点响应多个域,.NET 应用程序检查主机名,并相应地生成内容。例如,它可以在空白页中打印请求URL的名称。例如,www.first-domain.com 和 www.second-domain.com

web.config 在 system.webServer 节点下将相应的缓存、url压缩和 http压缩全部关闭。

aspx 页面将缓存控制标头设置为公共,其中包含未来的过期日期或 max-age 值。

访问 www.first-domain.com 会输出成功写入“www.first-domain.com”的页面。

但是,访问 www.second-domain.com 会输出一个写有“www.first-domain.com”的页面。

检查失败的请求跟踪,System.Web.Caching.OutputCacheModule 已找到缓存的输出(即使 .config 文件已关闭该功能),即使请求 URL 主机名不同,缓存也已匹配,因此只要设置了 max-age/expiry,第二个请求就会将第一个请求的结果输出到不同的域,然后才会出现第二个域的正确页面。

将缓存控制设置为私有,或者删除 web.config 中的“OutputCache”模块可以解决问题,同时维护发送到浏览器的正确缓存控制标头,但显然,我无法利用内核缓存我需要它。

我找不到任何有关如何配置 OutputCacheModule 的 MSDN 文档。

有其他人遇到过这个问题吗?我该如何启用内核缓存并让它考虑 URL 主机名(无需将应用程序分离到 IIS 中的不同站点)。

谢谢。

更新:

添加 SetSlidingExpiration 没有任何效果,因为无论请求主机名如何,内核缓存仍然会缓存输出。现在唯一的情况是禁用输出缓存,或者在它将运行的每个域上运行应用程序的重复实例 - 考虑到这将导致服务器性能下降,而不是使用输出缓存获得的性能提高,我们决定禁用此应用程序的输出缓存。

Have some strange behaviour regarding output caching in an ASP.NET 4 application on IIS 7.5. I've been able to repeat the problem simply on other empty setups, I'm certain this is a bug, but unsure how to report it to Microsoft.

A site in IIS responds to more than 1 domain, the .NET application examins the hostname, and produces content accordingly. For example, it may print the name of the request URL in a blank page. Eg, www.first-domain.com, and www.second-domain.com

The web.config has the appropriate caching, urlCompression, and httpCompression all turned OFF under the system.webServer node.

The aspx page sets the cache-control header for public, with either a future date for expires, or a max-age value.

Visiting www.first-domain.com outputs the page that successfully writes 'www.first-domain.com'.

However, visiting www.second-domain.com outputs a page that writes 'www.first-domain.com'.

Examining the failed-request-traces, System.Web.Caching.OutputCacheModule has found the cached output (even though the .config files have turned the function off), the cache has matched even though the request URL hostname are different, and thus the second request will output the results of the first request to the different domain for as long as the max-age/expiry was set for, before the correct page for the second-domain will appear.

Either setting cache-control to private, or removing the 'OutputCache' module in the web.config solves the problem, while maintaining the correct cache-control headers sent to the browser, but obviously, I can't take advantage of kernel caching when I need it.

I can't find any MSDN documentation on how the OutputCacheModule is configured.

Has anyone else experienced this issue, how can I go about enabling kernel caching and let it take into account URL Hostname (without separating the application to different sites in IIS).

Thanks.

Update:

Adding SetSlidingExpiration has no effect, as the kernal cache still caches the output regardless of the request hostname. The only scenario now is to either disable output caching, or run a duplicate instance of the app on each domain it will run - considering the drop in server performance this would result in vs. the increase of performance gained in using output caching, we decided to disable output caching for this app.

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

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

发布评论

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

评论(3

花开浅夏 2024-10-18 14:28:38

9个月后没有提供答案,也没有找到解决方案,只有一个解决方法,也许这会在IIS 7.5以上的下一个版本中修复...

--

添加 SetSlidingExpiration 没有效果,因为内核缓存仍然存在无论请求主机名如何,都会缓存输出。现在唯一的情况是禁用输出缓存,或者在它将运行的每个域上运行应用程序的重复实例 - 考虑到这将导致服务器性能下降,而不是使用输出缓存获得的性能提高,我们决定禁用此应用程序的输出缓存。

No answer has been provided after 9 months, and no solution has been found, only a workaround, perhaps this will be fixed in the next version of IIS greater than 7.5...

--

Adding SetSlidingExpiration has no effect, as the kernal cache still caches the output regardless of the request hostname. The only scenario now is to either disable output caching, or run a duplicate instance of the app on each domain it will run - considering the drop in server performance this would result in vs. the increase of performance gained in using output caching, we decided to disable output caching for this app.

小苏打饼 2024-10-18 14:28:38

我遇到了非常相似的问题,这里没有任何解决方案可以帮助我。

TLDR:强制删除 Web.config 上的 OutputCache 模块是我找到的唯一解决方案。

我的情况有点不同。

我在 Application_BeginRequest 中设置了 CORS,为呼叫我的特定主机应答 Access-Control-Allow-Origin(将其设置为 * 并没有一直可靠)。

我的控制器还为其响应设置了Cache-control: public

我的发现

每当我设置 Cache-control: public 时,IIS 都会强制缓存响应。 Application_BeginRequest 或我的控制器上的断点从未被再次命中。

通过 IIS 管理器禁用输出和内核缓存(如下所示)会让我遇到 Application_BeginRequest 断点,但永远不会让我进入控制器。有些东西仍在缓存响应。
禁用输出inetmgr 上的缓存和内核缓存

这篇文章建议从 IIS 中删除 OutputCache 模块会有所帮助。

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <remove name="OutputCache" />
  </modules>
</system.webServer>

这样做最终让我能够按下控制器。

什么会更有帮助

如果来自 MS 或非 MS 的人可以阐明是否有办法改变这种行为。 OutputCache 在应用程序的某些部分可能有用,而在其他部分则不必要。

当心

也许我(我们?)在这里解决了错误的问题。

也许 IIS 在这种情况下接管了缓存,因为它应该这样做。也许我的服务器和用户之间的代理的行为就像在这种情况下一样,如果是这种情况,那么在 IIS 上解决这个问题是错误的。我必须弄清楚这一点,也许你也应该这样做。

I was having a very similar problem and no solutions here helped me.

TLDR: Forcefully removing the OutputCache module on the Web.config was the only solution I found.

My scenario was a little bit different.

I have CORS set up in Application_BeginRequest, answering Access-Control-Allow-Origin for specific hosts that call me (setting it to * has not been reliable).

My Controller also sets Cache-control: public for it's responses.

What I found

Whenever I set Cache-control: public, IIS forcefully caches the response. Breakpoints on either Application_BeginRequest or my Controller were never hit a second time.

Disabling output and kernel caching via IIS Manager as seen below would have me hitting the Application_BeginRequest breakpoints, but never got me into the Controller. Something was still caching responses.
disabled output caching and kernel caching on inetmgr

This article suggested removing the OutputCache module from IIS would help.

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <remove name="OutputCache" />
  </modules>
</system.webServer>

Doing so allowed me to hit my Controller, finally.

What would help even more

If someone from MS or not could shine a light whether there is a way to change this behavior. OutputCache could be useful in some parts of an application and unnecessary in others.

Beware

Maybe I'm(we're?) solving the wrong problem here.

Maybe IIS was taking over caching in this scenario because it should. Maybe proxies along the way between my server and the user would behave just like that in that exact scenario, and if that's the case then working around this on IIS is wrong. I'll have to figure that out and maybe you should too.

雨后咖啡店 2024-10-18 14:28:38

我有类似的问题。我使用自定义 url 重写器。我有页面 example.com/articles 和 example.com/art-ANY_ID.html。两个 url 都映射到articles.aspx(在第二个示例中为articles.aspx?id=ANY_ID)。它在 ASP.NET 2.0 和经典管道模式下运行良好。在我们将其更改为 ASP.NET 4 和集成模式后,我们遇到了奇怪的行为:两个 url 返回相同的输出。它是任何页面,例如 example.com/art-ANY_ID.html。

现在,我们从 > 效果很好。我不明白为什么 http.sys 缓存它。

你找到任何解释了吗?

I have similar problem. I use custom url rewriter. I have pages example.com/articles and example.com/art-ANY_ID.html. Both url map to articles.aspx (in second example as articles.aspx?id=ANY_ID). It worked fine with ASP.NET 2.0 and Classic pipeline mode. After we have changed it to ASP.NET 4 and integrated mode, we have got strange behaviour: both url return identically output. It was any page like example.com/art-ANY_ID.html.

Now we removed <add extension=".html" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" /> from section <caching enabled="true" enableKernelCache="true"> and it fine works. I not understand why http.sys cache it.

Have you find any explanations?

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