3

In my Application_Start() method, how can I stop the execution of the ASP.NET application when certain conditions are not met?

Throwing an exception doesn't appear to work.

David Brown
  • 35,411
  • 11
  • 83
  • 132

3 Answers3

2

i don't think that's possible; even if you could 'abort' the startup, the next attempt to access a URL from the site would try to start it again

perhaps a static variable could be used to signal go/no-go, and begin_request could redirect to a placeholder page instead?

Steven A. Lowe
  • 60,273
  • 18
  • 132
  • 202
1

There seems to be a COM API that you can use for IIS administration. I think I'd try Environment.Exit() first, though.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
  • 1
    Environment.Exit() apparently also kills IIS and the entire AppPool. I had to restart both the Management Console and the AppPool that my application was running in before IIS would function correctly again. – David Brown Dec 20 '08 at 05:10
0

Do something that throws an unhandled error. Maybe throwing an Exception would be enough.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164