When to restart IIS when making changes to your application

Knowing when to restart IIS to pick up various types of changes to your application has traditionally been a challenge.

IIS and ASP.NET are both stateful software systems, which heavily rely on cached state that is loaded once to provide high performance.  They also recognize the downside of being stateful – having to refresh the state when the underlying data changes – and most of the time provide mechanisms for picking up the changes automagically (typically via file change notifications/ReadDirectoryChangesW).

As you can tell, that was a very general statement.  The reality of it is that it can be difficult to know when and how all the different things that are cached are picked up, how often, etc.

After I got asked about this for the 10,000th time, I figured I should provide a quick list of things that are cached and what to do to refresh them.

WARNING: This list is a simplification, and doesnt explain the reasons for why things are the way they are / go into detail.

Changes to:

I should …

IIS configuration


ASP.NET configuration


Content files (ASPX, ASP, static files)


/App_Code source code


.NET assemblies in /BIN

Do nothing, automatically detected


NOTE: In most cases, you need to make a request to the associated url to cause changes to be picked up


NOTE: During heavy load, sometimes changes may take a few seconds to be picked up due to file change notification lag


NOTE: Changes to application-level or machine-global configuration, /BIN directories, /App_Code, and multiple changes to content cause ASP.NET application restart


IIS configuration schema (e.g. adding new configuration section)


.NET assemblies in GAC


IIS/ASP.NET registry keys

Recycle application pool




IISRESET (if you don’t know which apppool)

Recyling an application pool is almost always a better alternative to IISRESET – its faster, and it keeps other applications / worker processes running unaffected.

To recycle an apppool (you can also of course do this from InetMgr.exe also, or from script/.NET code):

%windir%system32inetsrvappcmd recycle apppool <APPPOOLNAME>

Don't know which apppool, but know a url inside the application? Here is an example:

%windir%system32inetsrvappcmd list app http://localhost/myapp/index.html /xml | appcmd recycle apppool /in

How about, know the worker process PID? Try this:

%windir%system32inetsrvappcmd list wp 1234 /xml | appcmd recycle apppool /in

I have to make the disclaimer that there is definitely more complexity to this, especially when you start considering the impact that various changes have on your production system (ever make a config change, and watch the entire server thrash as all ASP.NET applications restart at the same time?).  For some insight on ASP.NET file change notifications, check out Thomas' excellent post on the topic: http://blogs.msdn.com/tmarq/archive/2007/11/02/asp-net-file-change-notifications-exactly-which-files-and-directories-are-monitored.aspx.

I'll post more details about the various change notification systems in play in the IIS/ASP.NET app stack in a later post if there is a strong interest, let me know …




Leave a Reply

Your email address will not be published. Required fields are marked *