how to handle problems in application_start in global.asax
Posted on 2008-06-16
Heres a quirky one.
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.
void Application_Error(object sender, EventArgs e)
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?