如何解决从iPad连接到Visual StudioIIS Express时的登录问题
我有一个已部署到Azure的MVC5应用程序。现在,要在本地进行测试,我使用Visual Studio(2019)运行我的应用程序,然后在移动设备浏览器中启动该网站。
问题在于,当我从iPad上登录并输入用户名/密码并单击“登录”后,我会立即返回登录屏幕。
我在iPad上尝试了不同的浏览器。我尝试清除它们上的缓存。我已经重新启动了PC和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);
我什至试图通过将以下代码放在我的Login 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,
,它便开始工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。