Thread: ASP.NET/enable output caching in ASP.NET

enable output caching in ASP.NET

 


Solution: enable output caching in ASP.NET

You cannot add an OutputCache directive on a master page. You must do the caching instructions programmatically, in code. Every content page that uses the master page needs output caching enabled.

protected void Page_Load(object sender, EventArgs e)

{

    // Use DateTime for expiration.

    Response.Cache.SetExpires(DateTime.Now.AddMonths(1));

 

    // HttpCacheability.Server means that the page will only be created once

    // on the server. Private means that the client is also allowed to cache.

    Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);

 

    // Indicate that the client's cache is valid until the item expires.

    Response.Cache.SetValidUntilExpires(true);

}




Re: enable output caching in ASP.NET

Original:


dotnetperls.com/Content/Output-Caching-Master-Page.aspx