首页 > 解决方案 > 登录表单 [RedirectFromLoginPage] 不起作用,母版页

问题描述

我正在处理 asp.net c# 中的登录页面,但是一旦我编写了代码,它就什么也不做。我正在使用 RedirectFromLoginPage,但代码和/或 .net 版本似乎有问题,我不能 100% 确定。

这是我的代码:

 protected void LoginForm_Authenticate(object sender, AuthenticateEventArgs e)
    {
        try
        {
            System.Threading.Thread.Sleep(1000);
            using (var context = new CompanyEntities())
            {
                //var collection = (from p in context.CP_BlockedAccounts where p.Email == LoginForm.UserName select p);
                ValidateIfCustomerIsBlocked Validator = new ValidateIfCustomerIsBlocked();
                if (Validator.Validate(LoginForm.UserName) == true)
                {
                    // Account Blocked
                    // Blocked_Alert.Visible = true;
                    // Blocked_Alert_Label.Text = "¡Lo sentimos!, al parecer su cuenta se encuentra bloqueada temporalmente, por favor comuniquese con nosotros lo antes posible para resolver su problema.";
                }
                else
                {
                    var query = (from p in context.CP_Register where p.Email == LoginForm.UserName && p.Password == LoginForm.Password select p);
                    foreach (var item in query)
                    {
                        FormsAuthentication.RedirectFromLoginPage(item.Email, false);
                        API.CompanyId.CompanyIdentity = item.Id;// Id of the company, global variable
                    }
                }
            }
        }
        catch (Exception ex)
        {
            LoginForm.FailureText = ex.ToString();
        }
    }

加载此页面后,它会重定向到与母版页链接的仪表板页面,这是我在母版页上的代码:

protected void Page_Init(object sender, EventArgs e)
    {
        if (!this.Page.User.Identity.IsAuthenticated)
        {
            FormsAuthentication.RedirectToLoginPage();
            Session.RemoveAll();
            Session.Abandon();
            FormsAuthentication.SignOut();
        }
        else
        {
            if (CompanyId == 0)
            {
                Session.RemoveAll();
                Session.Abandon();
                FormsAuthentication.SignOut();
                Response.Redirect("~/Login");
            }
            else
            {
                //this.Bind_Header();
                //string ImageURL = "~/API/Handlers/Image.ashx?User=" + CompanyId.ToString();
                //DropDownImage.ImageUrl = ImageURL;
                //MainImage.ImageUrl = ImageURL;
                //ImageSideBar.ImageUrl = ImageURL;
            }
        }
    }

我使用的信息是正确的,例如密码和电子邮件/用户名,但是一旦它进入母版页,它就会说用户没有经过身份验证。

有人可以帮我解决这个问题吗?

提前致谢。

标签: c#asp.netwebformsmaster-pages

解决方案


我刚刚解决问题的方法是在 web.config 中注释以下代码行。

<system.webServer>
<modules>
  <!--<remove name="FormsAuthentication" />-->
  <remove name="ApplicationInsightsWebTracking" />
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />

感谢所有帮助我的人。 这通常发生在创建新项目时。


推荐阅读