Max Tenenbaum

Max Tenenbaum

  • NA
  • 33
  • 47.9k

This web page has a redirect loop

Aug 19 2011 6:05 AM

Hi,

Can someone inspect the following code and tell me why I am getting the following error message:

"This web page has a redirect loop"


Code behind: proposal.aspx.cs


protected void Page_Load(object sender, EventArgs e)

    {
        ActiveDirectoryHelper.ActiveDirectoryHelper adh = new ActiveDirectoryHelper.ActiveDirectoryHelper();
        string loginName = Page.User.Identity.Name.Split('\\')[1];  
        ADUserDetail ThisUser = adh.GetUserByLoginName(loginName);

        if (ThisUser.Company == "co1)")

        {
            Response.Redirect("Proposal.aspx?Company=One");
        }

        else if (ThisUser.Company == "co2")

        {
            Response.Redirect("Proposal.aspx?Company=two");
        }

        else if (ThisUser.Company == "co3")

        {
            Response.Redirect("Proposal.aspx?Company=three");
        }
    }

Main page: proposal.aspx

<%

   string Company = Request.QueryString["Company"];

   switch (Company)

    {
        case "one":
            Response.Write("Proposal content is for Company1");
            break;

        case "two":

            Response.Write("Proposal content is for Company2");
            break;

        case "three":

            Response.Write("Proposal content is for Compnay3");
            break;
    }            

%>


Answers (6)

0
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Aug 19 2011 6:53 AM
See if this is any better:

        string url = Request.Url.ToString()

        if (ThisUser.Company == "co1)" && !url.Contains("Company=one"))
        {
            Response.Redirect("Proposal.aspx?Company=one");
        }

        else if (ThisUser.Company == "co2" && !url.Contains("Company=two"))
        {
            Response.Redirect("Proposal.aspx?Company=two");
        }

        else if (ThisUser.Company == "co3" && !url.Contains("Company=three"))
        {
            Response.Redirect("Proposal.aspx?Company=three");
        }
Accepted Answer
0
Satish Bhat

Satish Bhat

  • 0
  • 1.2k
  • 5.2k
Aug 19 2011 8:26 AM
I got it now.. I missed that view completely. :( Thanks 
0
Vulpes

Vulpes

  • 0
  • 96k
  • 2.6m
Aug 19 2011 7:42 AM
The problem was that (sometimes) Max was redirecting to the current page which was causing the loop.

The code I added was to make sure that he only redirected to a different page.
0
Satish Bhat

Satish Bhat

  • 0
  • 1.2k
  • 5.2k
Aug 19 2011 7:29 AM
Nice solution Vulpes, But still I can't figure out why original code was causing a loop :( Any help?
0
Max Tenenbaum

Max Tenenbaum

  • 0
  • 33
  • 47.9k
Aug 19 2011 6:25 AM
Unfortunately same result in all browsers and I have removed all cookies too.
0
Satish Bhat

Satish Bhat

  • 0
  • 1.2k
  • 5.2k
Aug 19 2011 6:17 AM
I think you are opening the site in Google Chrome. Try the site in IE.

If error is only happening in Google Chrome, solution is to clear cookies and site data.
REF