Coffka
Coffka

Reputation: 759

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?

Upvotes: 3

Views: 10027

Answers (1)

Kevin Junghans
Kevin Junghans

Reputation: 17540

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.

Upvotes: 1

Related Questions