redirection if session object is nothing

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
 
P

Patrice

You need only to this once once per request (for example in the beginrequest
event. See the global.asax file documentation for details).
 
G

graphicsxp

But I can't do a redirection in this event as global.asax is not a
page. Response.Redirect wouldn't work there.
 
P

Patrice

System.Web.HttpContext.Current gives access to the current Http request (and
in particular the Response objet).
 
G

graphicsxp

TRUE. But you can't do a response.Redirect in the Global.asax. Just
try, you will raise an exception.
 
P

Patrice

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...
 
G

graphicsxp

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...
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top