Response.redirect not working

When the control reaches the response.redirect line, the following error is generated in the browser. The url in response.redirect is correct.
Page not redirected properly

Firefox has detected that the server redirects the request to this address in a way that will never be completed.

*   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);
        }
    }
}
+3
source share
2 answers

Maybe you are redirected to an infinite loop? Here is a link to some information about this error.

If you have code as shown below for two pages, this can 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

, , , cookie.

+2

, .

+1

Source: https://habr.com/ru/post/1753390/


All Articles