从 iPad 连接到 Visual Studio (IIS Express) 时出现登录问题
Login issue when connecting to Visual Studio (IIS Express) from iPad
我有一个部署到 Azure 的 MVC5 应用程序。现在,为了在本地测试它,我 运行 我的应用程序使用 Visual Studio (2019),然后我在我的移动设备浏览器中启动该网站。
问题是,当我从 iPad 执行此操作并登录时,输入 username/password 并单击登录后,我立即返回到登录屏幕。
我在 iPad 上尝试过不同的浏览器。我试过清除它们的缓存。我已经重新启动了我的电脑和 iPad。仍然是同样的问题。我没有看到任何错误。 但如果我使用 iPhone 登录或从桌面浏览器 登录,它会起作用。如果部署到Azure,我可以从任何地方登录,包括iPad.
我在代码中调试,我什至看到登录成功并且 return 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,
后,它开始工作了。
我有一个部署到 Azure 的 MVC5 应用程序。现在,为了在本地测试它,我 运行 我的应用程序使用 Visual Studio (2019),然后我在我的移动设备浏览器中启动该网站。
问题是,当我从 iPad 执行此操作并登录时,输入 username/password 并单击登录后,我立即返回到登录屏幕。
我在 iPad 上尝试过不同的浏览器。我试过清除它们的缓存。我已经重新启动了我的电脑和 iPad。仍然是同样的问题。我没有看到任何错误。 但如果我使用 iPhone 登录或从桌面浏览器 登录,它会起作用。如果部署到Azure,我可以从任何地方登录,包括iPad.
我在代码中调试,我什至看到登录成功并且 return 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,
后,它开始工作了。