Minor Optimization - asp:LoginStatus control

Topics: Business Logic Layer, Themes
Dec 20, 2007 at 7:28 PM
We were stepping through the debugger, and were surprised at why PostBacks were required for logins and logouts. If you watch what happens in the postback, the entire object hierarchy is exercised (site.master-->BlogBasePage-->Page processing-->Control Processing) before the postback actually does a silly redirect to the login.aspx.

On your side panels (~/themes/Standard/SidePanel.aspx) - or whereever you use the control, the use of the asp:LoginStatus control can be replaced with:
Change:
<asp:LoginStatus runat="Server" LoginText="Sign in" LogoutText="Sign out" EnableViewState="false" />
to
<% if (Page.User.Identity.IsAuthenticated){ %>
<a id="logout" href="login.aspx?signout=true">Sign out</a>
<%}
else
{ %>
<a id="login" href="login.aspx">Sign in</a>
<%}%>

I think it's a lot cleaner this way, and you avoid an unnecessary postback.

One Caveat here is that by not using the LoginStatus control, and hard coding login.aspx into the page, you lose the declarative aspect of your web.config file. Small Price to pay I guess.
<authentication mode="Forms">
<forms timeout="129600" name=".AUXBLOGENGINE" protection="All" slidingExpiration="true" loginUrl="login.aspx" cookieless="UseCookies" />
</authentication>

Hope this helps...