简体   繁体   中英

response.redirect doesnt work

When control reaches response.redirect line then the following error is produced in browser. the url in response.redirect is correct.
The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

*   This problem can sometimes be caused by disabling or refusing to accept
      cookies.

here is the code

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage : System.Web.UI.MasterPage
{    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void imgbtnLogin_Click(object sender, ImageClickEventArgs e)
   {
        UserFunction objUser = new UserFunction();
        UserProperties objUserProperties = new UserProperties();
        IUserFunction iUserFunction = (IUserFunction)objUser;
        objUserProperties.UserName = txtUserName.Text;
        objUserProperties.Password = txtPassword.Text;
        string userName = txtUserName.Text; ;
        string password = txtPassword.Text; ;
        DateTime login = DateTime.Now;
        DateTime? logout = null;
        int UserId;
        string StartUpPage;
        bool success = iUserFunction.ValidateUser(objUserProperties, out StartUpPage);
        if (success)
        {
            Session["UserId"] = objUserProperties.UserId;
            Session["RoleId"] = objUserProperties.RoleId;
            Session["UserName"] = objUserProperties.UserName;
            Session["MyTheme"] = objUserProperties.Theme;
            iUserFunction.AddLoginHistory(objUserProperties.UserId, login, logout, 1);
            Response.Redirect(StartUpPage);

        }
        else
        {
            Label1.Text = "Wrong UserName/password.";
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Invalid Credential');", true);
        }
    }
}

Could it be that you are redirecting to an endless loop? Here is a link to some info for that error.

If you had code like below for the two pages this could happen.

Page1.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
   Response.Redirect(Page2Url);
}

Page2.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
   Response.Redirect(Page1Url);
}

UPDATE

If you are positive it's not an infinite loop in your code I would follow the steps in this link and see if the issues is caused by cookies.

您正在重定向到同一页面,导致无限循环。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM