[英]Login issue when connecting to Visual Studio (IIS Express) from iPad
I have an MVC5 app which is deployed to Azure. Now, to test it locally, I run my app using Visual Studio (2019), then I launch the site in my mobile devices browser.我有一个部署到 Azure 的 MVC5 应用程序。现在,为了在本地测试它,我使用 Visual Studio (2019) 运行我的应用程序,然后在我的移动设备浏览器中启动该站点。
The issue is that when I do it from my iPad, and login, after I enter username/password, and click login, I am back to the login screen immediately.问题是,当我从我的 iPad 执行此操作并登录时,输入用户名/密码并单击登录后,我立即返回到登录屏幕。
I have tried different browsers on the iPad. I have tried clearing the cache on them.我在 iPad 上试过不同的浏览器。我试过清除它们的缓存。 I have restarted my PC, and my iPad. Still the same problem.我已经重新启动了我的电脑和我的 iPad。仍然是同样的问题。 I don't see any errors.我没有看到任何错误。 But it works if I use my iPhone to login or from a desktop browser .但如果我使用我的 iPhone 登录或从桌面浏览器登录,它会起作用。 If it is deployed to Azure, I can login from everywhere, including iPad.如果部署到Azure,我可以从任何地方登录,包括iPad。
I debug in the code and I even see that the login is successful and the return URL is the right URL:我在代码中调试,我什至看到登录成功并且返回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);
I even tried to force things by putting the following code at the top of my Login POST method:我什至试图通过将以下代码放在我的登录 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();
Can someone help please?有人可以帮忙吗? Thank you.谢谢你。
Hopefully, this will some day save someone's hours of work.希望有一天这会节省某人的工作时间。 The problem was due to having the CookieSameSite in the Startup.Auth.cs:问题是由于 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))
}
});
Once I removed CookieSameSite = SameSiteMode.Strict,
, it started to work.一旦我删除CookieSameSite = SameSiteMode.Strict,
,它就开始工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.