问题
We've come across a rather annoying bug in IIS7.5 where it occasionally removes the contents of the tag in the web.config. It doesn't just remove the contents at runtime, it actually physically updates the file.
On our local machines it happens when we rebuild everything (which includes replacing application.config from source control) and on our server machines it happens on app pool restart. Both cases are intermittent.
It seems to be happening because we have some config at the root of the config and some in a location tag. The reason we do this is because we have some virtual applications underneath the root application and we don't want them to inherit the handlers and modules. We have the root system.webserver tag because there are some settings (like validateIntegratedModeConfiguration) that we want to inherit.
It only affects the system.webserver settings not inside the location tag. If you move everything into the location tag it is fine.
Our web.config looks something like this:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
...
</system.webServer>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules>
...
</modules>
<handlers accessPolicy="Read, Script">
...
</handlers>
</system.webServer>
</location>
Anyone else come across this problem?
回答1:
We ended up moving the configuration out of the root system.webserver and into the one inside the location tag. Then we also added it to all the child applications.
<location path="." inheritInChildApplications="false">
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
...
</modules>
<handlers accessPolicy="Read, Script">
...
</handlers>
</system.webServer>
</location>
Though it's not an ideal workaround, it has solved the problem with the configuration being removed.
来源:https://stackoverflow.com/questions/11562572/settings-from-system-webserver-sometimes-removed-from-web-config-file