redirection if session object is nothing

  • Thread starter Thread starter graphicsxp
  • Start date Start date
G

graphicsxp

Hi,
I'm trying to figure out the best way to redirect the user to a special
page when in my code i'm trying to use a Session object and that one is
nothing. Oviously I could do:

if Session("myObject") is nothing then
response.redirect("SessionExpired.aspx")
else

endif

but i'm not going to do that for each time i want to use a session
object.

Can someone think of a clever way?

Thank you
 
You need only to this once once per request (for example in the beginrequest
event. See the global.asax file documentation for details).
 
But I can't do a redirection in this event as global.asax is not a
page. Response.Redirect wouldn't work there.
 
System.Web.HttpContext.Current gives access to the current Http request (and
in particular the Response objet).
 
TRUE. But you can't do a response.Redirect in the Global.asax. Just
try, you will raise an exception.
 
There is a problem but not this one. The thing I forgot is that the session
state is not available at this early stage. You'll have to use a later event
such as AcquireRequestState (it works here).

For "redirect", note that it always raises an internal exception you
shouldn't catch...
 
How do you actually check whether the Session has expired in
Applicatin_AcquireRequestState ?

Other problem: if you do a response.redirect in this event, that leads
to an infinite state, a kind of infinite loop trying to do multiple
redirections...
 
Back
Top