Get current user id in ASP.NET Identity 2.0

前端 未结 4 1387
余生分开走
余生分开走 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:17

    Just in case you are like me and the Id Field of the User Entity is an Int or something else other than a string,

    using Microsoft.AspNet.Identity;
    
    int userId = User.Identity.GetUserId();
    

    will do the trick

提交回复
热议问题