Asp.NET Identity 停止在 Chrome 上工作

Spo*_*ook 6 asp.net cookies google-chrome asp.net-identity

由于某种未知原因,我无法再在 Chrome 上登录我自己的应用程序。

这是我登录的方式:

    [AllowAnonymous]
    [HttpPost]
    public async Task<ActionResult> Login(LoginModel model)
    {
        if (User.Identity.IsAuthenticated)
            return RedirectToAction("Index", "Home");

        if (!ModelState.IsValid)
            return View();

        var status = await signInManager.PasswordSignInAsync(model.Login, model.Password, true, false);
        switch (status)
        {
            case Microsoft.AspNet.Identity.Owin.SignInStatus.Success:
                {
                    int userId = User.Identity.GetUserId<int>();
                    if (userManager.IsFirstLogin(userId))
                    {
                        return RedirectToAction("Declaration", "Home", new { returnUrl = model.ReturnUrl });
                    }

                    return RedirectToLocal(model.ReturnUrl);
                }
            default:
                return View();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我调试了代码并且 PasswordSignInAsync 成功,但是 Chrome 显示没有为页面设置 cookie。实际上重定向到操作,标记为 [Authorize] 属性再次重定向到登录页面。

我在 IE 上测试了站点,一切正常,我可以登录和注销,并且 cookie 设置正确。

如果我能提供更详细的信息,请告诉我。


编辑:更多细节

我一直在测试一个对日期时间敏感的应用程序(在特定日期后停止显示)。我将系统时间更改为 2016 年 8 月 1 日,登录然后切换回现在。那是一切都停止工作的时候。

奇怪的是,当我切换回未来的时间时,我可以再次登录并且会话 cookie 设置正确。但是当我回到“现在”时,我无法再次登录。

Dav*_*ška 0

仍然需要调查发生了什么,但对我来说,“修复”是更改 Auth cookie 的名称。

在 Startup.Auth.cs 中:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    CookieName = $"SomeCustomNameForAuthCookie",
    Provider = ...
}); 
Run Code Online (Sandbox Code Playgroud)

我怀疑我的计算机上有很多可供开发的网站,并且都具有相同的默认 cookie 名称。