Output cache in content and master page

半腔热情 提交于 2019-12-02 00:50:36

问题


Two questions:

1. If I have a content page and a master page and I put this inside my content page:

<%@ OutputCache ...%>

Does it cache the whole page or only the content page portion?

2. How can I apply OutputChace in the master page?

I have a master page that has a lot of content pages that uses it. I want to apply the same outputcache profile on all of them, but I dont want to go one by one and change them.

Thanks.


回答1:


The whole page is cached. Edit
You can use user controls to cache portions.

As by the comments, if you want to cache all pages that are using a specific master page, you need the following code in the master page

 protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
            Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
            Response.Cache.SetValidUntilExpires(true);
        }



回答2:


Content page only will be cached; unless that content page is using the master page, in which case master page also will be cached.

Unlike a content page you can't use OutputCache directive for master page. See the below links

Cache Master Page in ASP.NET

http://www.dotnetperls.com/output-cache

http://forums.asp.net/t/1236981.aspx



来源:https://stackoverflow.com/questions/6575819/output-cache-in-content-and-master-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!