views:

226

answers:

3
+1  Q: 

Response.Redirect

What is the difference between calling Response.Redirect from the codebehind of a page, versus calling HttpContext.Current.Response.Redirect from a shared method on another class?

When I call HttpContext.Current.Response.Redirect it is giving me a 404 error sometimes, when calling Page.Respsone.Redirect doesn't.

EDIT:

Oops, my mistake, it was a typo.

+9  A: 

There is no difference between the two methods (the getter for Page.Request simply returns a reference to HttpContext.Current.Request - you have to dig a bit in Reflector but it's there) - the HTTP404 you see as a result is the response from the server and is totally dependent on the value passed to the Redirect method.

Andrew Hare
I agree- By looking at the Web server logs it should be easily apparent why the 404 is occurring.
RichardOD
+1  A: 

I was under the impression they referred to the same thing. What does your code look like?

Hugoware
+1  A: 

You'll only get the 404 error if your URL points to a non-existent page. These two methods are the same, it's your code that'll be the problem.

Paddy