为什么在本地部署ASP.NET 4.6应用程序到IIS 10服务器后,用户不能进行认证?

 2023-02-15    281  

问题描述

在我的ASP.NET Web表单应用程序中,我正在使用ASP.NET Identity 2.2进行成员资格系统.发展阶段按预期工作.用户获得身份验证并根据其角色访问网站的不同区域.

部署到IIS 10本地服务器后,身份验证被推翻.登录是成功的,但用户不进行身份验证.登录页面再次加载空和新鲜.我知道登录是通过在重定向前创建的文字创建的一些测试来成功的.

为什么在本地部署ASP.NET 4.6应用程序到IIS 10服务器后,用户不能进行认证?

这是登录方法:

protected void LogIn(object sender, EventArgs e)
    {
        if (IsValid)
        {
            // Validate the user password
            var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
            var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();

            List<ApplicationUser> us = manager.Users.ToList();

            foreach (var user in us)
            {
                textSuccess.Text += user.UserName + ": ";
                foreach (var role in user.Roles)
                {
                    textSuccess.Text += role.RoleId + ", ";
                }
            }
            // This doen't count login failures towards account lockout
            // To enable password failures to trigger lockout, change to shouldLockout: true
            var result = signinManager.PasswordSignIn(Email.Text, Password.Text, true, shouldLockout: false);

            switch (result)
            {
                case SignInStatus.Success:
                    panelSuccess.Visible = true;
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                    break;
                case SignInStatus.LockedOut:
                    Response.Redirect("/Account/Lockout");
                    break;
                case SignInStatus.RequiresVerification:
                    Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}", 
                                                    Request.QueryString["ReturnUrl"],
                                                    RememberMe.Checked),
                                      true);
                    break;
                case SignInStatus.Failure:
                default:
                    FailureText.Text = "Înregistrare eșuată";
                    ErrorMessage.Visible = true;
                    break;
            }
        }
    }

我该怎么办?综合管道的Outin配置可能会出现问题吗?

推荐答案

最终,在进行解决分辨率的所有可能的路径之后,我发现问题是cookie身份验证的配置.我会在这里发布任何悲惨的研究人员.

在 startup.auth.cs中文件中,我有:

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))
                }
            });

因为我在我的开发服务器上使用HTTPS,但不是在我部署了网站的IIS服务器上,所以 cookieseCureption.always 选项阻止了后者的身份验证.在这种情况下, cookieseCureption.sameasrequest 选项,这是默认的,是真正的正确选择.

以上所述是小编给大家介绍的为什么在本地部署ASP.NET 4.6应用程序到IIS 10服务器后,用户不能进行认证?,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/33804.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。