Solved

how to handle problems in application_start in global.asax

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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