The following code will help avoid excessive trips to the database:
SitePrincipal cachedNewUser = (SitePrincipal)Session["cachedNewUser"];
if(!(cachedNewUser == null))
{
Context.User = cachedNewUser;
}
else
{
cachedNewUser = new SitePrincipal( Context.User.Identity.Name );
Session["cachedNewUser"] = cachedNewUser;
Context.User = (SitePrincipal)Session["cachedNewUser"];
}
Warning - You Cannot use absolute URL's for links or redirects, only
relative paths. This is because the User.Context will be set back to
GenericPricipal when Absolute addresses are interpreted by IIS.
I learned this the hard way by coding absolute paths in my Global.asax.cs file and using them in the SiteHeader control.
The original Phile code for SitePage does not suffer from this because the Context.User is being reset (albeit via a trip to the db) EVERY time a page is loaded.
I hope this helps!
Shawn Cohan
info@allsquared.com