Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.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
C# Net核心身份锁定未锁定用户帐户_C#_Asp.net Core 3.1_Asp.net Core Identity - Fatal编程技术网

C# Net核心身份锁定未锁定用户帐户

C# Net核心身份锁定未锁定用户帐户,c#,asp.net-core-3.1,asp.net-core-identity,C#,Asp.net Core 3.1,Asp.net Core Identity,我尝试启用锁定功能,但未成功。每次我检查数据库时,AccessFailedCount都会增加到1,但在这之后,它会再次变为0。怎么了 我的代码是: //Login page code public async Task<IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (

我尝试启用锁定功能,但未成功。每次我检查数据库时,AccessFailedCount都会增加到1,但在这之后,它会再次变为0。怎么了

我的代码是:

//Login page code

    public async Task<IActionResult> OnPostAsync(string returnUrl = null) {
        returnUrl = returnUrl ?? Url.Content("~/");

        if (ModelState.IsValid) {

            var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: true);
            if (result.Succeeded) {

                _logger.LogInformation("User logged in.");
                return LocalRedirect(returnUrl);
            }
            if (result.RequiresTwoFactor) {
                return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
            }
            if (result.IsLockedOut) {
                _logger.LogWarning("User account locked out.");
                return RedirectToPage("./Lockout");
            }
            else {
                ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                return Page();
            }
        }

        // If we got this far, something failed, redisplay form
        return Page();
    }


//services code 
// Lockout settings.
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts = 2;
options.Lockout.AllowedForNewUsers = true;
//登录页面代码
公共异步任务OnPostAsync(字符串returnUrl=null){
returnUrl=returnUrl??Url.Content(“~/”);
if(ModelState.IsValid){
var result=await _signInManager.PasswordSignInAsync(Input.UserName、Input.Password、Input.RememberMe、lockoutOnFailure:true);
if(result.successed){
_logger.LogInformation(“用户登录”);
返回LocalRedirect(returnUrl);
}
if(结果要求系数){
return RedirectToPage(“./LoginWith2fa”,新的{ReturnUrl=ReturnUrl,RememberMe=Input.RememberMe});
}
如果(结果IsLockedOut){
_logger.LogWarning(“用户帐户锁定”);
返回重定向Topage(“/锁定”);
}
否则{
AddModelError(string.Empty,“登录尝试无效”);
返回页();
}
}
//如果我们走到这一步,有些东西失败了,重新显示形式
返回页();
}
//服务代码
//锁定设置。
options.Lockout.DefaultLockoutTimeSpan=TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts=2;
options.locket.AllowedForNewUsers=true;

您是如何获取AccessFailedCount的?请检查获取的正确方法我使用的是.net core 3.1,因此我没有获取AccessFailedCount。因为我希望signInManager来处理它。@U oz你所说的“之后它又变成0”是什么意思。我的意思是它不是锁定,而是再次计数为0。我想出了这个问题。如果在添加用户后更改锁定设置,则旧用户不会生效。只有新用户才能使用它。