从iPad连接到Visual Studio(IIS Express)时出现登录问题



我有一个MVC5应用程序,它已部署到Azure。现在,为了在本地测试它,我使用Visual Studio(2019(运行我的应用程序,然后在移动设备浏览器中启动该网站。

问题是,当我在iPad上进行登录时,在输入用户名/密码并单击登录后,我会立即返回登录屏幕。

我在iPad上尝试过不同的浏览器。我试过清除它们的缓存。我已经重新启动了我的电脑和iPad。还是同样的问题。我没有看到任何错误但如果我使用iPhone登录或从桌面浏览器登录,它会起作用。如果它部署到Azure,我可以从任何地方登录,包括iPad。

我在代码中调试,甚至看到登录成功,返回的URL是正确的URL:

var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, true);
switch (result)
{
case SignInStatus.Success:
await UserManager.SetLockoutEndDateAsync(user?.Id, new DateTimeOffset(DateTime.UtcNow));
await UserManager.ResetAccessFailedCountAsync(user?.Id);
return RedirectToLocal(returnUrl);

我甚至试图通过将以下代码放在登录POST方法的顶部来强制执行:

AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

System.Web.HttpContext.Current.Session.Clear();
System.Web.HttpContext.Current.Session.Abandon();

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

有人能帮忙吗?非常感谢。

希望有一天这能节省某人的工作时间。问题是由于Startup.Auth.cs:中有CookieSameSite

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
ExpireTimeSpan = TimeSpan.FromDays(14),
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
SlidingExpiration = true,
CookieSameSite = SameSiteMode.Strict,
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(TimeSpan.FromMinutes(30), (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});  

一旦我移除了CookieSameSite = SameSiteMode.Strict,,它就开始工作了。

最新更新