How To Restart ASP.Net Applications

Feb 23, 2009
by:   Tim Stanley

Many times, from an administration perspective, it's desirable to restart an ASP.NET web site without restarting IIS on the whole server.

One quick way to do this is to leverage the fact that the application has a cache dependency on the Web.Config file.  Writing to the Web.Config file will cause IIS to restart the ASP.NET application.  We can also leverage the fact that changing the last update time on the Web.Config will also force a restart of the application.

This will clear all cache and tracing information and has an obvious impact on performance and should only be done from an administration security controlled page.

   1: String szXMLFile;
   2: szXMLFile = System.Web.HttpRuntime.AppDomainAppPath;
   3: szXMLFile += "Web.Config";
   4: File.SetLastWriteTime(szXMLFile, System.DateTime.Now);
Add to favorites Send to a friend Digg It! DZone It! StumbleUpon Technorati Reddit Del.icio.us NewsVine Furl BlinkList