Change in IIS MMC setting may cause unwanted restarts of W3SVC

Recently we have discovered an issue with IIS Manager wherein changing settings in a certain way may cause unexpected restart of World wide Web Publishing Service. And this may happen before you realize until you go back to the Application event log and find entries corresponding to the W3SVC restart event as shown below:

Event Type:    Information
Event Source:    ASP.NET 2.0.50727.0
Event Category:    None
Event ID:    1023
Date:        4/22/2008
Time:        6:35:20 AM
User:        N/A
Computer:    SAURABSI-SEC
Restarting W3SVC

Event Type:    Information
Event Source:    ASP.NET 2.0.50727.0
Event Category:    None
Event ID:    1025
Date:        4/22/2008
Time:        6:35:25 AM
User:        N/A
Computer:    SAURABSI-SEC
Finish restarting W3SVC

Also as part of the above symptom, you will see IIS mmc paused like in a hung state (you may see a transient hour glass).
So what are the steps you need to be cautious of especially in a production environment?

First, a little background...

If you intend to change the version of ASP.Net through IIS manager by going to the Web Site properties --> ASP.Net tab, you should be fully aware that W3SVC service will get restarted in order to reflect the change. Restarting of W3SVC will lead to all the application pools getting recycled along with it, hence leading to all your currently running web applications to spawn new worker processes for further requests. This is by design and if you want to circumvent the recycling of other application pools not corresponding to your website, you should have a way to control W3SVC restart after the version change. You can do so by following this excellent post by Jerry Orman.

So far so good. But I have something else to disclose too.

Let's say you go to the IIS manager, select a Web site, go to its properties and poke around with different settings. At some point you visit ASP.Net tab (even if you do not modify any settings like current ASP.Net version) and move out from there to some other tab. On this tab if you do any change(s), and you click on Apply and then OK (in the same order) bang!, your W3SVC service will restart and all your application pools will recycle subsequently as a result of it.

Here are some quick steps to reproduce the problem, follow it to believe it.

1) Open IIS manager (Start -> Run -> inetmgr.exe)
2) Select any website --> right click and select properties
3) Click on ASP.NET TAB - do not change or modify anything - just click on the TAB.


4) Now click on any other TAB and change some values (for example: go to website tab and change port to say 8080 from 80)
5) Hit apply
6) Hit OK
7) This will restart W3SVC and you will see following event in application event logs.

In the above steps the key points are basically to visit the ASP.NET TAB and then click on Apply and then OK to reproduce the issue.

Why is this behavior?
The reason this behavior occurs is in the code where we make a check to see if ASP.NET runtime version is changed and if yes we need to fire W3SVC restart. We are comparing the selected version of ASP.NET TAB with what has been changed incorrectly. There is an additional code in place that checks for the QFE versions of the ASP.NET framework installed, but in the IIS manager UI, we only give an option to either select 1.x.xxxx or 2.0.xxxxx. We really don’t care about the QFE versions installed after that. But the code that gets executed on OK or APPLY does. For the 1st execution (i.e. click on APPLY) it’s correctly able to remove the QFE information from the version string it retrieved (i.e. 2.0.xxxxx, instead of 2.0.xxxxx.QFE), the check is successful noting that nothing is changed in ASP.NET TAB, and hence no restart of W3SVC is required. But now when we go ahead with 2nd execution (i.e. click on OK) the same code executes again and this time the version information string is truncated further to RTM (i.e. to 2.0 from 2.0.xxxxx) and thus the check fails (ASP.Net version is changed from 2.0.xxxxx to 2.0), which incorrectly indicates that ASP.NET runtime version has been changed and thus calls a restart of W3SVC.

In short, you could click anywhere in UI all day long, but for you to reproduce this issue, you need to
1) Go to ASP.NET UI once.
2) Click APPLY and OK (both in that order). If you only click OK then the code gets executed only once and hence correctly and would not restart the w3svc.

Latest update on this:

We have informed the Product group about this issue. A Knowledge base article is in work.