Raising Exceptions in HttpApplication.Init

U

Urs Eichmann

Upon startup of my ASP.NET 2.0 application, I check if the application
configuration is in an acceptable state inside an override of
HttpApplication.Init(). If not, I raise an exception from this method.

Everything fine so far.

But I noticed that, the next time the application gets called, the Init
method is not being called anymore, even tough it ended with an
exception the last time (which means that Init was not completed).
Instead, Session_Start is being called as if the initialisation
succeeded.

Is there a way to actually tell the ASP.NET framework that the
initialisation of the application was not successful and that it should
repeat the initialisation the next time a session is opened?

Thanks for any help
Urs
 
K

Karl Seguin [MVP]

this is all I can think of early in the morning:

Init{
TryLoadConfiguration();
}
function TryLoadConfiguration()
{
//do stuff
bool successfullyLoaded = true/false;

HttpApplication.Add("IsLoaded", successfullyLoaded );
if (!successfullyLoaded )
{
throw new exception
}
}

Application_BeginRequest (or session_start)
if (((bool)HttpApplication("IsLoaded")) == false)
{
TryLoadConfiguration();
}


in other words, keep track of whether or not you've successfully loaded in
the application variable.

One has to wonder, what is it in Init that might fail once but then suddenly
start working? Typically, if configuration stuff fails, the site should
crash until someone manually fixes it and restarts it.

Karl
 
U

Urs Eichmann

Hi Karl,
thanks for your suggestion. I was hoping that there is a more "elegant"
solution which I overlooked.
ne has to wonder, what is it in Init that might fail once but then suddenly
start working? Typically, if configuration stuff fails, the site should
crash until someone manually fixes it and restarts it.

The problem is, if the configuration isn't right the site might work
for the first page, then suddenly bombing out on the next page. I want
to make sure that not even the first page is being displayed in case of
configuration errors.

Urs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top