views:

42

answers:

1

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" %>

and i have used the 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 ascx.cs file,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 Still the page shows the same content for both logged in user and Guest user. My objective is to to have the Page being cached except the content inside the substitution control. Any idea how to achieve this ? Thanks in advance

+1  A: 

You are going to want to cache multiple versions of your page. You will want one for the Logged in view and one for the guest view. You can set the two different views either by VaryByParams or VaryByHeaders.

http://msdn.microsoft.com/en-us/library/aa719665%28v=VS.71%29.aspx

Glennular