簡體   English   中英

登錄表單[RedirectFromLoginPage]不起作用,母版頁

[英]Login form [RedirectFromLoginPage] not working, Master Pages

我正在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;
            }
        }
    }

我正在使用的信息是正確的,例如密碼和電子郵件/用戶名,但是一旦進入母版頁,則表明用戶未通過身份驗證。

有人可以幫我解決這個問題嗎?

提前致謝。

我剛剛解決問題的方法是在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" />

謝謝大家的幫助。 創建新項目時通常會發生這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM