简体   繁体   中英

Extending claims identity in MVC5 application

My mvc5 application uses aspnet.identity authentication. Owin middleware is configured to use application cookies. All i want to achieve is to show user full name instead of the login in the LoginPartial view.

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

I guess i need to customize my identity during creating it with user manager. Am I right?

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

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

I know I can store it in the session but what is the right way to store additional information?

You can use claims to store the user's full name. Here is an article on how to add and retrieve custom claims using ASP.NET Identity .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM