Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Raising Exceptions in HttpApplication.Init

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Urs Eichmann - 13 Feb 2006 11:02 GMT
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
Karl Seguin [MVP] - 13 Feb 2006 12:30 GMT
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

Signature

http://www.openmymind.net/

> Upon startup of my ASP.NET 2.0 application, I check if the application
> configuration is in an acceptable state inside an override of
[quoted text clipped - 14 lines]
> Thanks for any help
> Urs
Urs Eichmann - 13 Feb 2006 15:42 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.