身份核心,持久登录不是持久

时间:2020-07-30 07:30:17

标签: asp.net-core asp.net-identity asp.net-core-2.2

我遇到一个奇怪的问题。我有两个网站,一个是另一个的克隆。 在第1个网站(原始网站)上,登录名是永久性的,除非用户选择自行注销,否则他们不会注销。

两个网站都运行ASP.NET Core 2.2

网站#1登录代码:

[HttpPost("login")]
public async Task<IActionResult> Login(LoginVM model)
{
    if (ModelState.IsValid)
    {
        var signInAttempt = await _signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);
        if (signInAttempt.Succeeded)
        {
            if (!string.IsNullOrEmpty(model.ReturnUrl))
            {
                return Redirect(model.ReturnUrl);
            }
            return RedirectToAction("Home");
        }

        if (signInAttempt.IsLockedOut)
        {
            ModelState.AddModelError("", _stringLocalizer["User is locked out"]);
        }
        else
        {
            ModelState.AddModelError("", _stringLocalizer["Email and password do not match"]);
        }
    }
    return View(model);
}

在网站#2(克隆)上,登录不是持久性的,并且一段时间后用户将注销-我不确定会持续多长时间。

网站#2的登录代码:

[HttpPost("login")]
public async Task<IActionResult> Login(LoginVM model)
{
    if (ModelState.IsValid)
    {
        var signInAttempt = await _signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);
        if (signInAttempt.Succeeded)
        {
            if (!string.IsNullOrEmpty(model.ReturnUrl))
            {
                return Redirect(model.ReturnUrl);
            }
            return RedirectToAction("Home");
        }

        if (signInAttempt.IsLockedOut)
        {
            ModelState.AddModelError("", _stringLocalizer["User is locked out"]);
        }
        else
        {
            ModelState.AddModelError("", _stringLocalizer["Email and password do not match"]);
        }
    }
    return View(model);
}

因此,从上面可以看到,两个代码完全相同-持久性都设置为true。 在网站的启动文件中,它们也相同:

网站#1 Startup.cs:

services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    // Configure identity options here.
    options.Password.RequireDigit = false;
    options.Password.RequiredLength = 4;
    options.Password.RequireLowercase = false;
    options.Password.RequireNonAlphanumeric = false;
    options.Password.RequireUppercase = false;
}).AddEntityFrameworkStores<ApplicationDbContext>();

services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = "/login";
    options.LoginPath = "/login";
    options.LogoutPath = "/logout";
});

网站#2 Startup.cs:

services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
    // Configure identity options here.
    options.Password.RequireDigit = false;
    options.Password.RequiredLength = 4;
    options.Password.RequireLowercase = false;
    options.Password.RequireNonAlphanumeric = false;
    options.Password.RequireUppercase = false;
}).AddEntityFrameworkStores<ApplicationDbContext>();

services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = "/login";
    options.LoginPath = "/login";
    options.LogoutPath = "/logout";
});

所以,我的问题是:如何在网站#2上实现永久登录?

更新: 回收应用程序池时,用户也会注销-网站1上也不会发生这种情况。

0 个答案:

没有答案