Code is as follows: login the user token and deposit account
public void SignIn (string token, string name)
{
ClaimsIdentity ClaimsIdentity=new ClaimsIdentity (CookieUsrAuthInfo AuthenticationScheme);
ClaimsIdentity. AddClaim (new Claim (ClaimTypes NameIdentifier, token));
ClaimsIdentity. AddClaim (new Claim (ClaimTypes. Name, Name));
ClaimsPrincipal ClaimsPrincipal=new ClaimsPrincipal (claimsIdentity);
_httpContextAccessor. HttpContext. SignInAsync (CookieUsrAuthInfo AuthenticationScheme, claimsPrincipal);
}
This time by GetCurrentUser () method to get the Principal value
public SysUserAccount GetCurrentUser ()
{
Var result=_httpContextAccessor. HttpContext. AuthenticateAsync (CookieUsrAuthInfo. AuthenticationScheme). The result;
Var token=result. Principal. FindFirstValue (ClaimTypes. Sid);
Return _sysUserAccountService. GetLogged (token);
}
Action for:
var getUsr=_userAuthService. GetCurrentUser ();
Run code debugging when no error found in, but for the result. The Principal, FindFirstValue (ClaimTypes. Sid); To obtain, the Principal is empty
Startup. Cs configuration has a configuration, a mystery
Startup. Cs configuration:
CodePudding user response:
Add an error messageCodePudding user response:
Save wrote ClaimTypes NameIdentifier here,When read from ClaimTypes. Read the Sid, so will be null,
Keep consistent can solve the problem:)