簡體   English   中英

表單身份驗證redirecttologin頁面不起作用

[英]formsauthentication redirecttologinpage doesn't work

我有一個login.aspx。 其中有一個用於重定向頁面的代碼。

Server.Transfer(string.Format("~/admin/FillUserExtraInfo.aspx?UserName={0}",Server.UrlEncode(loginInitial.UserName)));

它確實起作用,然后在FillUserExtraInfo.aspx中

protected void Page_Load(object sender, EventArgs e)
    {
        // retrieve the username from the querystring
        userName = this.Request.QueryString["UserName"];
        string mode = UsefulFunctions.GetOperatingMode();
        if (mode == ConfigurationSettingValues.OperatingModes.Backup.ToString())
            FormsAuthentication.RedirectToLoginPage();

但是FormsAuthentication.RedirectToLoginPage()不起作用。 該程序將繼續執行,直到Page_Load的末尾,然后最終返回登錄。

更新:在此期間,我發現了URL http://localhost:53906/Login.aspx?ReturnUrl=%2fLogin.aspx%3fAction%3dLogout

最后。 但我得到一個錯誤:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

我的web.config:

<authentication mode="Forms">
        <forms loginUrl="Login.aspx" protection="All" timeout="30" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
    </authentication>

我的問題:

  1. 為什么FormsAuthentication.RedirectToLoginPage()不起作用?
  2. 如何處理我遇到的錯誤?

謝謝。

第二次更新:我在FormsAuthentication.RedirectToLoginPage()之后添加了Response.End(),然后它可以工作,但是異常仍然存在。

請嘗試使用Response.Redirect(“ url”,false)而非Server.Transfer()。

Response.Redirect("~/admin/FillUserExtraInfo.aspx?UserName=" + Server.UrlEncode(loginInitial.UserName) + "", false);

參考

暫無
暫無

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

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