简体   繁体   English

我可以让用户的浏览器缓存 MVC3 页面吗?

[英]Can I make it so the uesr's browser will cache an MVC3 page?

I have pages that stay the same from week to week.我的页面每周都保持不变。 Every time a user requests them they are regenerated again.每次用户请求它们时,它们都会重新生成。

I have set up the following for static:我为 static 设置了以下内容:

  <system.webServer>
    <staticContent>
      <clientCache cacheControlCustom="public" cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
    </staticContent>
  </system.webServer>

Is there something that I can do to make the dynamic pages also cache?我可以做些什么来使动态页面也缓存吗?

This is not set on your pages (Views) but on your Actions.这不是在您的页面(视图)上设置的,而是在您的操作上设置的。
There is an OutputCache ActionFilter you can use:您可以使用一个OutputCache ActionFilter

public class HomeController : Controller
{
    [OutputCache(Duration=10, VaryByParam="none")]
    public ActionResult Index()
    {
        return View();
    }

}

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

相关问题 使用MVC3 Webgrid,如何在会话中保留网格,以便可以返回到以前的页面? - Using MVC3 Webgrid, how do I preserve the grid in the session so I can return to the page I was on before? 如何在 MVC3 的 Razor 页面上使用枚举? - How can I use Enums on my Razor page in MVC3? 使用MVC3,我可以调用/使用另一个项目中的视图吗? - With MVC3 can I call / use a view that's in another project? MVC3模型-如何使它成为下拉菜单? - MVC3 model - how to make it so editorfor is a dropdown? 如何使MVC4向用户展示不会被浏览器缓存的页面? - How can I make MVC4 present a page to the user that will not be cached by the browser? 如何在MVC3中重定向页面? - How do I redirect page in MVC3? 如何提高每页的第一页的ASP.Net MVC3性能? - How do I improve ASP.Net MVC3 performance on each page's first hit? 除了将用户的浏览器定向到目标网址之外,如何使页面上的所有链接触发操作? - How can I make all links on a page trigger an Action in addition to directing the user's browser to the destination url? 如何使用集合成员类型为对象制作MVC3编辑器表单? - How can I make MVC3 Editor Form for Object with collection member type? 如何在MVC3 Razor的foreach循环中显示无序列表? - How can I make an unordered list appear within a foreach loop in MVC3 Razor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM