Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 使用每个请求的声明手动验证用户_Asp.net Core_Asp.net Identity_Asp.net Core 2.1_Asp.net Identity 3_Asp.net Core 2.2 - Fatal编程技术网

Asp.net core 使用每个请求的声明手动验证用户

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

我正在API上使用ASP.NET Core 2.2和ASP.NET Identity

是否可以手动验证每个请求的用户声明


我想在初始开发阶段使用它…

为了在不进行日志记录的情况下对用户进行身份验证,您可以尝试:

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});
返回视图();
}