I'm trying to get custom fields for an Identity object so that on the page side, I can simplify references to the logged-in user.
WizBang.aspx
Welcome <b><%: Page.User.Identity.FirstName %></b>
Your username is<%: Page.Use开发者_JAVA百科r.Identity.Name %>!
My other thought is to just stick it into session and set it via a Application_PostAuthenticateRequest
listener and not mess with the whole Identity in the first place. Or if there is any other way that is better.
Application_PostAuthenticateRequest
is the correct way to set a custom IIdentity. I suggest that you add a static property to your identity:
public MyCustomIdentity : IIdentity
{
public static MyCustomIdentity Current { get { return (MyCustomIdentity) Thread.CurrentPrincipal.Identity; }}
}
And access it like <%= MyCustomIdentity.Current.SpecialProperty %>
in your view.
精彩评论