Solved

how to handle problems in application_start in global.asax

Posted on 2008-06-16
2
2,297 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now