Response.Redirect in Application_Start & Session_Start

C

csn

Is it possible to have a Response.Redirect in Global.asax in the
Application_Start and Session_Start events?

We have code in both events, with try-catch blocks, and if an exception is
caught, we wanted to redirect to an error page. But, this doesn't seem to
work.

So, another question is, if an exception is thrown and caught in a catch
block in Application_Start and/or Session_Start, what do we or can we do
with it?

Thanks.
 
S

Steve C. Orr [MVP, MCSD]

You can't do this.
The Application_Start event is not associated with any user, therefore you
cannot redirect a user from it.
If I caught an exception in there I'd probably log it.
 
J

Juan T. Llibre

re:
Is it possible to have a Response.Redirect in Global.asax
in the Application_Start and Session_Start events?

The Application_OnStart event occurs before the first
new session is created, before the Session_OnStart event.

Only the Application and Server built-in objects
are available within Application_OnStart.

Referencing the Session, Request, or Response objects
in the Application_OnStart event script causes an error.

However, all the built-in objects are available and
can be referenced in the Session_OnStart event script.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================
 

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

Top