Response.Redirect problem

  • Thread starter Thread starter sjledet
  • Start date Start date
S

sjledet

I'm trying to figure out what I have wrong in the following code. It's
located at http://www.ledet.com/locations/location.aspx

If I call this page with http://www.ledet.com/locations/location.aspx?id=0
it works fine and redirects to the default page for that directory.
But if I call it with http://www.ledet.com/locations/location.aspx?id=188
it doesn't redirect

Does anyone have any suggestions?

----------------------------------------------------------------------------------------------------------

// Get locationID variable from the querystring. If there is now id
variable, redirect back to the main location page.
this.locationID = this.Request.QueryString.Get("id") != null ?
Convert.ToInt32(this.Request.QueryString.Get("id")) : 0;


if (this.locationID == 0)
{
this.Response.Redirect("default.aspx");
}

if (this.locationID==188)
{
this.Response.Redirect("http;//www.ledet.com/vilt/default.aspx");
}
 
sjledet said:
I'm trying to figure out what I have wrong in the following code. It's
located at http://www.ledet.com/locations/location.aspx

If I call this page with http://www.ledet.com/locations/location.aspx?id=0
it works fine and redirects to the default page for that directory.
But if I call it with http://www.ledet.com/locations/location.aspx?id=188
it doesn't redirect

What does it do, then?
Does anyone have any suggestions?

----------------------------------------------------------------------------------------------------------

// Get locationID variable from the querystring. If there is now id
variable, redirect back to the main location page.
this.locationID = this.Request.QueryString.Get("id") != null ?
Convert.ToInt32(this.Request.QueryString.Get("id")) : 0;


if (this.locationID == 0)
{
this.Response.Redirect("default.aspx");
}

if (this.locationID==188)
{
this.Response.Redirect("http;//www.ledet.com/vilt/default.aspx");

That should be "http:", not "http;".
 
Fixed the typo. Same behavior. What it does is just execute the rest
of the page with locationID as 188. It executes the SQL statement
based on that parameter later and returns the records associated with
location ID 188.

For reference, the declaration for the variable is:

protected int locationID, i;

just n case that matters

I had tried doing it relative and then tried the full path, but the
fact that it didn't error out proves it wasn't getting called.

Is it something in the syntax of:

this.locationID = this.Request.QueryString.Get("id") != null ?
Convert.ToInt32(this.Request.QueryString.Get("id")) : 0;
 
sjledet said:
Fixed the typo. Same behavior. What it does is just execute the rest
of the page with locationID as 188. It executes the SQL statement
based on that parameter later and returns the records associated with
location ID 188.

For reference, the declaration for the variable is:

protected int locationID, i;

just n case that matters

I had tried doing it relative and then tried the full path, but the
fact that it didn't error out proves it wasn't getting called.

Is it something in the syntax of:

this.locationID = this.Request.QueryString.Get("id") != null ?
Convert.ToInt32(this.Request.QueryString.Get("id")) : 0;

I don't see anything in your code that is wrong. You have to do some
debugging to find out what's really happening in the code.

You can skip the check for null, though, as Convert.ToInt32(string)
already does that and returns zero if the argument is null.

locationID = Convert.ToInt32(this.Request.QueryString["id"]);
 
Fixed the typo. Same behavior. What it does is just execute the rest
of the page with locationID as 188. It executes the SQL statement
based on that parameter later and returns the records associated with
location ID 188.

For reference, the declaration for the variable is:

protected int locationID, i;

just n case that matters

I had tried doing it relative and then tried the full path, but the
fact that it didn't error out proves it wasn't getting called.

Is it something in the syntax of:

this.locationID = this.Request.QueryString.Get("id") != null ?
Convert.ToInt32(this.Request.QueryString.Get("id")) : 0;

when you are debugging this guy, what does locationID look like when
it comes out of that check? When you pass in 188 in your query
string, do you get 188 out? Also what happens if you cahnge your
statement to:

locationID = int.Parse(Request.QueryString.Get("id));

I know that that is a dumb/dangerous cast but I am guessing that
Convert.ToInt32 is giving you back something other than 0 when you
pass 188.
 
Does anyone have any suggestions?

Response Redirect the way you are using it here should redirect the
page, but will do so only AFTER the rest of the page code has
completed executing. Depending on how the rest of the code is
written this could be your problem since some techniques can negate
the redirect. There is a simple solution you can try to see if this
might be the case.

Assuming that your location id is being retreived from the Querystring
correctly and you are executing the redirect logic inside the IF
statement (which all seems to be valid), try using the following
overload for your redirect statement (note changing the semi-colon ';'
typo after the HTTP to a colon ':' as well):

this.Response.Redirect("http://www.ledet.com/vilt/
default.aspx", true);

The boolean parameter TRUE after the URL indicates execution of the
current code should terminate immediately and the redirection should
occur at that time and not wait for the rest of the code to process
(FALSE is the default value if a parameter is not supplied). If your
problem is caused by the rest of the code executing, this should take
care of it.
 
Response Redirect the way you are using it here should redirect the
page, but will do so only AFTER the rest of the page code has
completed executing.

Sorry, but that is not correct.

For that to happen you would have to call Response.Redirect(url, false).
Depending on how the rest of the code is
written this could be your problem since some techniques can negate
the redirect. There is a simple solution you can try to see if this
might be the case.

Assuming that your location id is being retreived from the Querystring
correctly and you are executing the redirect logic inside the IF
statement (which all seems to be valid), try using the following
overload for your redirect statement (note changing the semi-colon ';'
typo after the HTTP to a colon ':' as well):

this.Response.Redirect("http://www.ledet.com/vilt/
default.aspx", true);

The boolean parameter TRUE after the URL indicates execution of the
current code should terminate immediately and the redirection should
occur at that time and not wait for the rest of the code to process
(FALSE is the default value if a parameter is not supplied

No, it's not.

Here is the actual code from the HttpResponse class in system.web.dll:

public void Redirect(string url)
{
this.Redirect(url, true);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top