Get ASP.NET Identity Current User In View

后端 未结 4 1561
無奈伤痛
無奈伤痛 2020-12-30 05:01

I use ASP.NET Identity 2.0 and MVC. I need to logged user\'s name,surname,email etc.. in view. How can get it? I can get just @User.Identity but there no my user class\'s pr

4条回答
  •  粉色の甜心
    2020-12-30 05:55

    There are two ways you can achieve this.

    1) Create your own CustomPrincipal by inheriting IPrincipal interface to include Name, Surname and Email using this example or this one.

    2) Get details directly from the database and pass it as a model to the view.

    Method one will be good option if you want to use same user details in several views, but method two is the simplest way to achieve this. let me know if you need any code help for the second method.

提交回复
热议问题