Has anybody ever seen the IIS worker process overwriting the machine.config? After installing the .NET 4.5 framework on our QA servers we are seeing this issue.
Here’s the background:
We have an asp.net website that was built in the .NET 4.0 framework. It creates archives (zip files) for users to download. All was good until we installed the 4.5 framework on the server. Immediately after installing the .NET 4.5 framework on the server, we started noticing that users were losing their sessions and being taken back to the logon page randomly.
After some investigation, we discovered that IIS was creating the following event logs:
1:30:48 PM - Application is shutting down. Reason: Configuration changed.
1:30:54 PM - Application is starting.
Furthermore, using Procmon, we saw the following event happening at the same time:
Name: w3wp.exe
Version: 7.5.7600.16385 (win7_rtm.090713-1255)
Operation: CreateFile
Result: SUCCESS
Path: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
This is occurring on servers running Windows Server 2008, Windows Server 2008 SP2, Windows Server 2008 R2, and Windows Server 2008 R2 SP1. Uninstalling the .NET 4.5 framework (and then re-installing the 4.0 framework because apparently uninstalling 4.5 uninstalls 4.0) makes the problem go away. Reinstalling the 4.5 framework makes the problem immediately appear.
I was able to add code to our Global.asax.cs file to log when the Session_Start event is being called, and sure enough, Session_Start is called at the same time as the spontaneous logouts.
It was suggested that perhaps our code is creating too many files under the inetpub\wwwroot structure (even though they are outside of the application root for the website) and therefore IIS was creating too many file watchers. We added a registry entry to set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\FCNMode=1 and to our surprise, the spontaneous restarts seem to have gone away. For those that aren’t familiar with that registry setting, it disables the creation of file watchers within IIS, meaning that now whenever we turn over new libraries to our bin folder or make web.config changes, we must manually restart IIS because there are no file watchers monitoring for changes.
Long-term, yes, we would like to move our zip files out of the inetpub folder and stream them using an ashx, but for now the zips we create are in a directory parallel to the application root (for example, our website is in e:\inetpub\wwwroot\blah\ourwebsite and we’re writing the zip files to e:\inetpub\wwwroot\blah\zips).
So, the question is, has anybody else seen this? Turning off IIS’s file watchers seems to make the problem go away, but it really doesn’t seem to explain why the w3wp.exe process would have been overwriting the machine.config file. Also, it doesn’t make any sense as to why this problem only occurs with the .NET 4.5 framework installed on the machine. Even with code compiled targeting 4.0, the mere presence of the 4.5 framework causes the issue to happen.
We have “clean roomed” the server, using a shiny new virtual with nothing else on it (even without antivirus software) and the problem occurs.
Help? :-)