How to restart an ASP.NET application

Things have been crazy-busy lately, and there is a short list of things I’d like to blog about. But until things calm down a bit, here’s a quick one that I’m writing down more for myself, because I’ll likely forget this in the future.
 
Today, I had a website that did some stuff on application startup. The system it needed wasn’t there on startup, so it failed. My thinking was that throughout the day, when the site was idle, the application would subsequently restart, find the dependant system back up and recover. However, in real life – people were hitting the site all day, so it never had a chance to restart. So the question is: "How can I programatically restart a web application?".
 
Now, if you try to google an answer to that, you will likely find 1,001 hacks that modify the web.config, so that the app restarts. I thought/think that is a bit kludgy, so I continued searching and found: http://dotnetslackers.com/Community/blogs/haissam/archive/2008/07/25/restart-asp-net-application-programatically.aspx
 
The answer is quite simple, just use:
HttpRuntime.UnloadAppDomain()
Done and done – works like a charm!!
Posted in ASP.NET, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 2 other followers

%d bloggers like this: