Why can't users authenticate after deploying locally the ASP.NET 4.6 application to the IIS 10 server?

帅比萌擦擦* 提交于 2019-12-06 07:22:46

Eventually, after going all possible paths in search for a resolution, I have discovered that the problem was with the configuration of the Cookie Authentication. I'll post the reason here for any miserable researchers.

In the Startup.Auth.cs file, I had :
app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login.aspx"),
                CookieSecure = CookieSecureOption.Always,
                AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
                Provider = new CookieAuthenticationProvider
                {

                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
                }
            });

Because I was using HTTPS on my development server, but not on the IIS Server where I deployed the website, the CookieSecureOption.Always option prevented the authentication on the latter one. In this situation, CookieSecureOption.SameAsRequest option, which is the default, is the real proper choice.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!