A MasterPage is cached by the WebServer to give faster response to the user.

The caching occurs the first time it is the corresponding ContentPage is invoked.

Due to this fact the LoginView inside a Masterpage would be updated on some pages and would fail to update on others,
giving inconsistent results.

The solution to this problem is that you need to use control as seen below.

<div class="loginstatus">
      <asp:Substitution runat="server" ID="substituteLoginInfo" MethodName="methodToInvoke" />
</div>

The thing with control is that you need to point it to a static Method on the Masterpage Codebehind

It has the following signature :

public static string methodToInvoke(HttpContext context)
{
   return DateTime.Now.ToLongTimeString();
}

This method will return a HTML string that will be substituted in the page, hence the name of the control.

I read this on Scott Guthrie ‘s website and he referred to as “dough-nut cache”.

Where the cream part of the dough-nut is the substitution control which is not cached :)

Post to Twitter

Tags: , , ,