Solved

how to handle problems in application_start in global.asax

Posted on 2008-06-16
2
2,421 Views
Last Modified: 2012-08-14
Hi all,
Heres a quirky one.
In short:
Is there any way to catch errors in the Application_Start method of global.asax and display a custom error message to the user based on the problem?

In a bit more detail:
In the Application_Start method in my Global.asax file, I ve a call to the database to get some config settings. The connection details are pulled from web.config which is fine.
I also have a custom error page setup. If an error bubbles up Application_Error of global.asax catchs it and the Server.Transfer() method is called.
i.e.
void Application_Error(object sender, EventArgs e)
{
  Server.Transfer("~/CustomErrorPage.aspx");
}

This normally works fine, but I noticed there that it doesnt work when any exceptions are created during Application_Start (e.g. a database connection error). The Server.Transfer() method gives me a "error executing child request".

Basically, it looks like i cant use Server.Transfer() for errors in application start. So is there any way to catch an error in application start and display it gracefully.  Or is it just best to leave the full stack trace showing so the installers can see whats happened?

Thanks
d
0
Comment
Question by:CoreSupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
ajitha75 earned 250 total points
ID: 21794629
Application_Error will not handle errors in Application_Start. You will have to put a try/catch block in Application_Start and log the error.
Again here you cannot use Server.Transfer or Response.Redirect, because Server and Response objects would not have been initialized yet.

0
 

Author Comment

by:CoreSupport
ID: 21794800
Hey ajitha75
Yes, I tried Response.Redirect and saw it wouldnt work.
Ok thats what I thought, that I would have to use the default error screen.
Just thought I was missing something.
Thanks
D
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question