开发者

Custom Identity for User object in MVC 2.0

开发者 https://www.devze.com 2023-02-04 23:26 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号