2011-01-14 86 views
0

我想獲得一個標識對象的自定義字段,以便在頁面上,我可以簡化對登錄用戶的引用。在MVC 2.0中的用戶對象的自定義標識

WizBang.aspx 

    Welcome <b><%: Page.User.Identity.FirstName %></b> 
    Your username is<%: Page.User.Identity.Name %>! 

我的另一個想法是,只是它粘成會話,並通過與在首位整個身份Application_PostAuthenticateRequest聽衆,而不是亂設置。或者如果有其他更好的方法。

回答

0

Application_PostAuthenticateRequest是設置自定義IIdentity的正確方法。我建議你爲你的身份添加一個靜態屬性:

public MyCustomIdentity : IIdentity 
{ 
    public static MyCustomIdentity Current { get { return (MyCustomIdentity) Thread.CurrentPrincipal.Identity; }} 
} 

並在你的視圖中訪問它像<%= MyCustomIdentity.Current.SpecialProperty %>

+0

我該如何在該PostAuthenticate請求中使用我的身份?只需要替換當前的HTTPContext的?對不起,如果這似乎很明顯。 – ClutchDude 2011-01-14 23:18:04

相關問題