Jaspal
Jaspal

Reputation: 93

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);
        }
    }
}

Upvotes: 3

Views: 1484

Answers (2)

SLaks
SLaks

Reputation: 888203

You are redirecting to the same page, causing an infinite loop.

Upvotes: 1

Abe Miessler
Abe Miessler

Reputation: 85126

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.

Upvotes: 2

Related Questions