Solved

how to handle problems in application_start in global.asax

Posted on 2008-06-16
2
2,269 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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

11 Experts available now in Live!

Get 1:1 Help Now