Caching whole page except a user control in ASP.Net application
Approach 1)
As described in the following figure, the page is divided into 4 user controls, 3 of them are cached and 1 of the control that you want to load dynamically is not cached.
Gotcha: In this approach we have to make sure that we do not add the output cache directive (<%@ OutputCache Duration="86400" VaryByParam="none" %>) to the page.
User control 1 <%@ OutputCache Duration="86400" VaryByParam="none" %> | User control 4 (Not Cached)
|
User control 3 <%@ OutputCache Duration="86400" VaryByParam="none" %> | User control 4 <%@ OutputCache Duration="86400" VaryByParam="none" %> |
Approach 2)
In this approach you can use
This way the whole page is cached but the
ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MembersHome.aspx.cs" Inherits="MemberLogin" %>
<%@ OutputCache Duration="86400" VaryByParam="none" %>
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<asp:Substitution runat="server" ID="idSubstitution" MethodName="GetVerificationImage" />
body>html>
ASPX.CS
public partial class MemberLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e){}
public static string GetVerificationImage(HttpContext context)
{
return CommonFunctions.GenerateRandomString();
}
}
References:
Dynamically Updating Portions of a Cached Page
http://msdn.microsoft.com/en-us/library/ms227429.aspx
Substitution Class
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.substitution.aspx
ASP.NET Caching
http://msdn.microsoft.com/en-us/library/ms972379.aspx
Comments
Post a Comment