Last post Apr 08, 2011 05:28 AM by Dave Sussman
Apr 07, 2011 01:20 PM|will1968|LINK
When you cache a page I assume you are saving the rendered html that gets sent to the user who requested the page. What happens when the person who requests the page is logged in and their user name is displayed at the top of the page. This I assume will
change the html that is rendered and thus mean the cache is rebuilt?
If so is there any point caching pages in such a scenario as I assume there will be a performance penalty rebuilding and storing the cache all the time?
I am not sure if this makes any difference but all the pages have a master page and this is where the login is displayed.
Apr 07, 2011 03:01 PM|akhhttar|LINK
If the page has very dynamic behavior then output caching will be not be very helpful, you are right. But you can also configure the caching at control level, so if some part of the page is static ( Like footer, header, side menues) then you move that part
into User Control and use the out put caching for that control.
Please see following article to understand the asp.net caching
Apr 08, 2011 05:28 AM|Dave Sussman|LINK
Actually, you can use the substitution control. Eg, in your page:
Welcome <asp:Substitution id="s1" runat="server" MethodName="GetUserName" />
Then in code:
protected static string GetUserName(HttpContext context)
return context.User.Identity.IsAuthenticated ? context.User.Identity.Name : "guest";
The output cache module checks for substitutions before it returns the cached HTML; if it finds one it runs the appropriate method and the output from that is injected into the HTML. So the string returned has to be HTML, not server controls - remember,
we're outside of the page pipeline here. Also note that the method is static.