Restarting a .NET web application without restarting IIS

Sometimes you want or have to reset your web application, e.g. you did an update on some data, but the old data is still cached in the web application (most likely for performance) on the web server. Many of us will think about an ‘iisreset’, which might indeed be the easiest way to go, if you have access to the web server.

And that’s where problems arise. Quite a few web applications are hosted by another party, and most of these hosting parties don’t grant you enough access on the web server to do something like an ‘iisreset’. Or there might just be (few or more) different applications hosted on the same IIS which makes it impossible for you to do an ‘iisreset’. But still you need some way to restart the web application to clear the cache.

You can use one of the following ways to restart (*) the web application:

  • Edit the web.config file. Even adding and removing a space is enough, you only have to change the timestamp of the file. Some tools exist to ‘touch’ a file, like described by Scott Hanselman here.
  • Edit the global.asax file.
  • Change a file in the bin directory (or subdirectory) of the web application.
  • Create, rename or delete a directory in the web application directory.
  • Create a small page to use the HttpRuntime.UnloadAppDomain method.

This list is not limited to all possibilities, but gives you the most common ones. You can also see them as possible alternatives for the quite too often used ‘iisreset’.

When you experience problems with a running .NET web application, one of the reasons to investigate is whether your application is restarting more times than you expect. You can use the points mentioned above as a checklist to try and find out if this is the problem.

To conclude I wish you all the best for 2010.

(*): Actually the web application unloads and only restarts the next time a request for the application is done.

Licensed under CC BY-NC-SA 4.0; code samples licensed under MIT.
comments powered by Disqus
Built with Hugo - Based on Theme Stack designed by Jimmy