Asp.net core 使用每个请求的声明手动验证用户
我正在API上使用ASP.NET Core 2.2和ASP.NET Identity 是否可以手动验证每个请求的用户声明Asp.net core 使用每个请求的声明手动验证用户,asp.net-core,asp.net-identity,asp.net-core-2.1,asp.net-identity-3,asp.net-core-2.2,Asp.net Core,Asp.net Identity,Asp.net Core 2.1,Asp.net Identity 3,Asp.net Core 2.2,我正在API上使用ASP.NET Core 2.2和ASP.NET Identity 是否可以手动验证每个请求的用户声明 我想在初始开发阶段使用它…为了在不进行日志记录的情况下对用户进行身份验证,您可以尝试: public async Task<IActionResult> Login() { var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTy
我想在初始开发阶段使用它…为了在不进行日志记录的情况下对用户进行身份验证,您可以尝试:
public async Task<IActionResult> Login()
{
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "edward"));
identity.AddClaim(new Claim(ClaimTypes.Name, "edward zhou"));
//add your own claims
var principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = true });
return View();
}
公共异步任务登录()
{
var identity=newclaimsidentity(CookieAuthenticationDefaults.AuthenticationScheme,ClaimTypes.Name,ClaimTypes.Role);
identity.AddClaim(新的ClaimTypes.NameIdentifier,“edward”);
identity.AddClaim(新索赔(ClaimTypes.Name,“edward zhou”);
//添加您自己的声明
var principal=新的ClaimsPrincipal(身份);
等待HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,主体,新的AuthenticationProperties{IsPersistent=true});
返回视图();
}