Get current user id in ASP.NET Identity 2.0

前端 未结 4 1382
余生分开走
余生分开走 2020-12-13 05:48

I just switched over to using the new 2.0 version of the Identity Framework. In 1.0 I could get a user object by using manager.FindByIdAsync(User.Identity.GetUserId()

4条回答
  •  误落风尘
    2020-12-13 06:18

    In order to get CurrentUserId in Asp.net Identity 2.0, at first import Microsoft.AspNet.Identity:

    C#:

    using Microsoft.AspNet.Identity;
    

    VB.NET:

    Imports Microsoft.AspNet.Identity
    


    And then call User.Identity.GetUserId() everywhere you want:

    strCurrentUserId = User.Identity.GetUserId()
    

    This method returns current user id as defined datatype for userid in database (the default is String).

提交回复
热议问题