How to force an ASP.NET web app to exit?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

We have an ASP.NET web application that attempts to check some database
conditions in Application_start to ensure that all is well before the app
comes up. However, I figure out how to force the app to exit if this
verification fails. Just throwing an exception doesn't seem to do the trick.
The app still comes up.

I feel like I should be able to call Application.exit() inside of
Application_start, but of course there is no such thing here.

What is the best way to accomplish this?

thanks
Robb
 
Another way to say this is, I want to abort the startup. If that clarifies
what I'm trying to do.

thanks
Robb
 
You cant stop and application, technically you can abort startup with an
unhandled error exception like a file not found exception.
For application exceptions, the System.Web.HttpApplication class (the base
class for Global.asax) triggers the System.Web.HttpApplication.Error event
if you do not handle the error on the page or if you re-throw the exception
and this will terminate the application as it starts.

You can open, modfy and save the web.config file which will restart the
application on next requestshould you control the exception. Best if you
handle the false start and control your application shutdown and restart
however.
--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
Typically, two ways to handle this:

1) your error handler would decide that the user shouldn't get access, so it
would respond with an HTML stream... effectively a web page produced by
code, that explains that an error occurred. It is good form to provide a
link to a useful home page.

2) create two virtual directories in your app: one public with an error page
(and a login page, and any other pages that are available to the general
public) and the other as an application. If the app doesn't start up,
redirect the user to the error page in the other vdir.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Back
Top