Session stuff in app_xxx events

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

I think I've found my problem, but not sure what to do about it.

In the application_start, I have an operation that is erroring (on purpose
for my testing procedures). In the Application_error event, I am trying to
set a session var equal to the error message. However, this causes the
application to die. I am assuming that since app_start errored, session
state is not ever being initialized as even doing the following in app_error
causes the app to die:

dim a as string
a=session.sessionid
(I have proved out the above by creating a clean web app that does nothing
else than throw an error in app_start and ties to retrieve sessionid in
app_error...it doesn't work, no session info exists).

Since there is no per-user info at this point in the app's life, I also
can't redirect, so it always goes to the page specified in the web.config
file. Any way around that, either?

So, I need a way to tell if sessions are active or have been initialized for
the application yet so I know if I can safely use them in my error handling
or if I need to do it some other way in those instances where the error
happens in app_start. Can anyone shed light on how that might be done?
 
Jon said:
I think I've found my problem, but not sure what to do about it.

In the application_start, I have an operation that is erroring (on purpose
for my testing procedures). In the Application_error event, I am trying to
set a session var equal to the error message. However, this causes the
application to die. I am assuming that since app_start errored, session
state is not ever being initialized as even doing the following in
app_error causes the app to die:

dim a as string
a=session.sessionid
(I have proved out the above by creating a clean web app that does nothing
else than throw an error in app_start and ties to retrieve sessionid in
app_error...it doesn't work, no session info exists).

Since there is no per-user info at this point in the app's life, I also
can't redirect, so it always goes to the page specified in the web.config
file. Any way around that, either?

So, I need a way to tell if sessions are active or have been initialized
for the application yet so I know if I can safely use them in my error
handling or if I need to do it some other way in those instances where the
error happens in app_start. Can anyone shed light on how that might be
done?

Application-level events are a fairly unique time in an application's life.
These events are not for or about a particular user, so you can't use
anything that's user-specific.

Session state is user-specific, so you can't use it at all in
Application-level events.

There's no other magic that I know about.

Even when you're in user-specific code, are you sure you just want to
display the error to the user? I'd suggest implementing the Error
Application_Error event to put the error into the system event log or
something like that. Maybe even e-mail it to your sfaff.
John Saunders
 
Perhaps a better question would be to ask how to handle errors in the
application_Start procedure period. Any takers?
 
Jon said:
Perhaps a better question would be to ask how to handle errors in the
application_Start procedure period. Any takers?

Try-Catch?

What do you mean, "how to handle them"? What do you want to do about errors
there?

John Saunders
 

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

Back
Top