简体   繁体   English

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

[英]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.

相关问题 从Visual Studio连接到SQL Server Express - Connecting to SQL Server Express from Visual Studio 从 Visual Studio 2019 运行时在 IIS Express 上获取 NullReferenceException - Getting NullReferenceException on IIS Express while running from Visual Studio 2019 在 Visual Studio 上通过 IIS Express 运行时可以加载图像,但通过 IIS 运行时无法加载 - Image can load when running by IIS Express on Visual studio, but can't load when running by IIS 从Jenkins运行IIS Express时,MSSQLLocalDB登录失败 - Login Failed for MSSQLLocalDB when running IIS Express from Jenkins 在Visual Studio 2012中进行调试时将IIS Express更改为全功能IIS - Change IIS Express to full functions IIS when debug in Visual Studio 2012 在带有 SpaServices 和 Visual Studio 的 IIS Express 中启动时,如何防止我的本地主机端口在调试时发生变化? - How do I prevent my localhost port from changing while debugging when launching in IIS Express with SpaServices and Visual Studio? 连接到Visual Studio Express 2013 for Web中的数据库 - Connecting to database in Visual Studio Express 2013 for Web Visual Studio / IIS Express间歇性错误 - Visual Studio/IIS Express Intermittent Bugs Visual Studio 找不到 IIS Express - Visual Studio can't find IIS Express 使用IIS Express / Visual Studio进行SimpleInjector验证过程 - SimpleInjector Verification process with IIS Express / Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM