I have an ASP.NET page where I am trying to do some output caching, but ran into a problem. My ASPX page has
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MYProject._Default" %>
<%@ OutputCache Duration="600" VaryByParam="None" %>
<%@ Register TagPrefix="MYProjectUC" TagName="PageHeader" Src="~/Lib/UserControls/PageHeader.ascx" %>
<%@ Register TagPrefix="MYProjectUC" TagName="PageFooter" Src="~/Lib/UserControls/PageFooter.ascx" %>
I have a user control called "PageHeader" in the ASPX page. In PageHeader.ascx
, I have an ASP.NET Substitution
control, where I want to show some links based on the logged in user.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PageHeader.ascx.cs" Inherits="MyProject.Lib.UserControls.PageHeader1" %>
<div class="headerRow">
<div class="headerLogo">
<a href="Default.aspx"><img src="Lib/Images/header.gif" alt=""></a>
</div>
<div id="divHeaderMenu" runat="server">
<asp:Substitution ID="subLinks" runat="server" MethodName="GetUserProfileHeaderLinks" />
</div>
</div><!--headerRow-->
In my user control code-behind I have a static method which will return a string based on whether the used logged in or not using session:
public static string GetUserProfileHeaderLinks(HttpContext context)
{
string strHeaderLinks = string.Empty;
// check session and return string
return strHeaderLinks;
}
But the page still shows the same content for both logged in user and Guest user.
My objective is to to have the page be cached except the content inside the substitution control. How do I do this?