Get current user id in ASP.NET Identity 2.0

前端 未结 4 1368
余生分开走
余生分开走 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 05:56

    I had the same issue. I am currently using Asp.net Core 2.2. I solved this problem with the following piece of code.

    using Microsoft.AspNetCore.Identity;
    var user = await _userManager.FindByEmailAsync(User.Identity.Name);
    

    I hope this will be useful to someone.

提交回复
热议问题