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:
Done and done – works like a charm!!