response object

  • Thread starter Thread starter TJS
  • Start date Start date
T

TJS

how do I use "response.redirect" in a class ?

I'm getting an error on "response is not declared" when I try to compile
 
Any class cannot call Redirect, it has to have access to an HttpResponse
instance, for instance the Response property on a Page object. You would
need to provide the Page object to any methods that need to perform a
redirect.
 
there must be a simple solution...

if the condition fails I want to send them to an error page

how can this be done ?
 
Try System.Web.HttpContext.Current.Response.Redirect.

Of course if you try to use this when there is no http context available,
the Current property will evaluate to null, and trying to get its Response
property will throw a null reference exception.
 
Should have thought of that. Anyway, this is the same HttpResponse instance
that the Page object has.
 
If that is what you want, then you should be able to configure ASP.NET to
redirect to an error page when it receives an unhandled exception.
 
Hello TJS,

HttpContext.Current.Response.Redirect
there must be a simple solution...

if the condition fails I want to send them to an error page

how can this be done ?
 
Back
Top