How can I get the specific fields of the currently logged-in user in MVC5?

前端 未结 2 1195
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 02:08

I have an MVC5 app that uses Individual Authentication, and of course ASP.NET Identity. The point is that I had extended I have a model that inherits from ApplicationUser, i

2条回答
  •  独厮守ぢ
    2021-01-06 03:07

    Yes, in Identity, if you need additional user information, you just pull the user from the database, since this is all stored on the actual user object now.

    if (Request.IsAuthenticated)
    {
        var user = UserManager.FindById(User.Identity.GetUserId());
    }
    

    If GetUserId isn't on User.Identity, add the following to your usings:

    using Microsoft.AspNet.Identity;
    

提交回复
热议问题