3

我的mvc5應用程序使用aspnet.identity身份驗證。 Owin中間件配置爲使用應用程序cookie。 我想要實現的是在LoginPartial視圖中顯示用戶全名,而不是登錄名。在MVC5應用程序中擴展聲明標識

@Html.ActionLink("Hello, " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" }) 

我想我需要在使用用戶管理器創建時自定義我的身份。我對嗎?

private async Task SignInAsync(ApplicationUser user, bool isPersistent) 
    { 
     var identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); 

     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); 
    } 

我知道我可以將它存儲在會話中,但什麼是正確的方式來存儲額外的信息?

+0

我在這裏的答案是向身份標記添加聲明的簡短指南。 http://stackoverflow.com/questions/27683169/identity-2-0-creating-custom-claimsidentity-eg-user-identity-getuserbyidint/27694574#27694574 – Shoe

回答