User.Identity.GetUserId() returns null after successful login

后端 未结 9 2536
傲寒
傲寒 2020-12-05 09:52

I\'ve defined a temp variable to get current user id, it always returns null.

Here is the snapshot:

Why?

UPDATE:

         


        
9条回答
  •  温柔的废话
    2020-12-05 10:00

    HttpContext.User = await _signInManager.CreateUserPrincipalAsync(user);
    

    After signing in you can use the sign in manager to create the user principal and manually assign the HttpContext.User reference

    This will then allow you to access the user id like you would with a normal signed in page

    var userId = userManager.GetUserId(HttpContext.User);
    

提交回复
热议问题