Application_Start & Exceptions

G

Guest

Hi;

We can have an exception thrown in our Application_Start call. And if so, it
does then go to Application_Error. However, in this case in Application_Error
when we call: Server.Transfer("~/error.aspx"); - we get an exception.

I assume that since the application is just starting that it is not yet
possible to do a transfer. Is there another method in Global.asax that we
should do our initialization in? Or another way to send it to error.aspx once
initialization is complete?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
A

Alvin Bruney [MVP]

What exactly is the exception being fired during the start event? Posting a
stack trace would help.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
G

Guest

WindwardLicenseException - caused by not having a license key for our app in
their Web.Config. In this case we need to redirect every request on our app
to the page license.aspx.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




Alvin Bruney said:
What exactly is the exception being fired during the start event? Posting a
stack trace would help.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


David Thielen said:
Hi;

We can have an exception thrown in our Application_Start call. And if so,
it
does then go to Application_Error. However, in this case in
Application_Error
when we call: Server.Transfer("~/error.aspx"); - we get an exception.

I assume that since the application is just starting that it is not yet
possible to do a transfer. Is there another method in Global.asax that we
should do our initialization in? Or another way to send it to error.aspx
once
initialization is complete?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
S

Steven Cheng[MSFT]

Hello Dave,

For Application_Start/End they are two special events that different from
other events which associated with ASP.NET request's process pipeline. For
exception occured in Application_Start event, though it will be captured by
the "Application_Error" event, however, since at that time, the
ApplicationInstance hasn't been created yet, server.transfer won't work.
Server.Transfer is used for transfer during a request's context. For the
case that exception occur in Applciation_Start, you may use
Context.Response.Redirect.

Also, we can check the Context.ApplicationInstance == null to determine
whether it is a request during a valid worker request context.

e.g.


==================
void Application_Error(object sender, EventArgs e)
{

if(Context.ApplicationInstance != null)
Context.Server.Transfer("~/errorinfo.aspx");
else
Context.Response.Redirect("~/errorinfo.aspx");
}
==================


HOpe this helps.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top