Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 308
Patrick McDonald Avatar asked Aug 08 '26 01:08

Patrick McDonald


2 Answers

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.

like image 89
Andrew Hare Avatar answered Aug 11 '26 03:08

Andrew Hare


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.

like image 26
Paddy Avatar answered Aug 11 '26 03:08

Paddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!