如何在 IIS 7.5 上禁用服务器端缓存 (asp net mvc3)
我正在努力解决有关缓存的 IIS 设置,这里是我的问题的简要描述:
我正在为移动和非移动创建一个网站,共享相同的控制器。 IE:mysite/page 将提供 mysite/page.cshtml 或 mysite/M/page.cshtml,具体取决于设备。
问题是,它在我的本地和集成环境(cassiini 和 iis 6)中运行良好,但在另一台计算机(2008r2/iis 7.5)上,显然有一个积极的服务器端缓存策略:
- 如果我从台式机访问该网站,我有正确的页面(桌面版本)
- 如果现在我使用手机访问该网站,我将拥有桌面版本(这意味着服务器端缓存,我的手机没有)使用相同的网络)。
相反,如果我重新启动服务器并首先使用手机访问该网站,那么我将在桌面上获得移动版本(当然仅适用于我已经访问过的页面)。
到目前为止,我尝试了 2 个解决方案:
从 Web.config 禁用 OutputCache:
<httpModules>
[..]
<remove name="OutputCache" />
</httpModules>
并取消选中 IIS 中站点的“输出缓存”中的“启用输出缓存”。
困扰我的是,我的另一台服务器(iis 6.0)没有这个问题,尽管在这台服务器上启用了缓存,这让我认为它与 iis 7 缓存添加有关。
我的问题很简单:如何在 IIS 7.5 上禁用服务器端缓存?
提前感谢您的 iis 灯!
找到了!
抱歉,你们真的猜不到那个,我扩展了 RazorViewEngine (实际上我使用了一个示例移动 mvc3 模板应用程序),并且此类覆盖了 FindView,它应该考虑 useCache 参数,但显然无论我如何配置 IIS ,用iis7设置为true。我到处都把它设置为 false。明天我将研究对该参数的适当调整。
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
感谢你们的帮助,我现在对 IIS 的所有缓存可能性有了很好的了解;)。有趣的是,这与 IIS 7.0 的行为不同(IIS6 和 Cassiini 是一致的)。
编辑:
更多信息: http://aspnet.codeplex.com/workitem/8201?PendingVoteId= 8201 ,与FindView的调试/发布工作有关。
这正是我的问题: http://aspnet.codeplex.com/workitem/8201?PendingVoteId =8201
I'm struggling with my IIS setup regarding caching, here's a brief description of my problem:
I'm making a site for mobile and non-mobile, sharing the same controllers. IE: mysite/page will serve either mysite/page.cshtml, or mysite/M/page.cshtml, depending on the device.
Here's the catch, it worked fine with my local and integration environment (cassiini and iis 6), but on another machine (2008r2/iis 7.5), apparently there is an aggressive server-side caching policy:
- If I access the website from a desktop machine, I have the correct pages (desktop version)
- If now I use my mobile phone to access the site, I will have the desktop version, (which implies a server-side cache, my phone is not using the same network).
On the contrary, if I were to restart the server and access the site using my phone first, then I will get the mobile version on my desktop (only for the pages I already visited of course).
I tried 2 solutions so far:
Disabling OutputCache from my Web.config:
<httpModules>
[..]
<remove name="OutputCache" />
</httpModules>
And unchecking "Enable output cache" in "Output Caching" for my site in IIS.
What's bugging me is that I do not have this problem with my other server (iis 6.0), although caching is enabled on this one, which leads me to think it is related to iis 7 caching addition.
My question is simple: how does one disable server-side caching on IIS 7.5?
Thanks in advance for your iis lights!
Found it!
Sorry guys you could not really guess that one, I extend RazorViewEngine (actually I used a sample mobile mvc3 template app), and this class overrides FindView, it is supposed to take into account a useCache parameter, but apparently no matter how I configure IIS, it was set to true with iis7. I set it to false everywhere. I'll look into appropriate tuning of that parameter tomorrow.
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
Thanks for your help guys, I have a good understanding of all the caching possibilities with IIS now ;). It's interesting that this behaves differently with IIS 7.0 (IIS6 and Cassiini were consistent).
Edit:
More info: http://aspnet.codeplex.com/workitem/8201?PendingVoteId=8201 , it is related to debug/release working of FindView.
This was my exact problem: http://aspnet.codeplex.com/workitem/8201?PendingVoteId=8201
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在处理浏览器缓存。您是否分析过流量以查看 304?你可能在追寻错误的问题。
注意:您的缓存清除解决方案必须包括客户端和服务器端。
I think you are dealing with browser cache. Have you profiled the traffic to see the 304s? You may be chasing the wrong problem.
NOTE: Your cache busting solution has to include the client side as well as the server-side.
正如里克所说,您需要首先对此进行分析。不过,一个快速测试是实现一个无缓存控制器,正如我在此处概述的那样:
禁用整个 ASP.NET 网站的浏览器缓存
As Rick said, you need to profile this first. A quick test though would be to implement a no-cache controller as I outlined here:
Disable browser cache for entire ASP.NET website
如果您正在谈论图像等静态类型,您可以将其添加到 web.config
更新中:
这是 链接
此链接详细介绍了您想要执行的操作。
If you are speaking to static types such as images and such you can add this to your web.config
Update:
Here is a link
This link talks in detail about what you want to do.