I am trying to setup a really fast, compressed, cached static content website to serve only .jpg, .css and .js
I want to remove all functionality from the website configuration that is not required:
But this configuration keep failing:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<urlCompression doStaticCompression="true" doDynamicCompression="false" />
<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".gif" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".png" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".js" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".css" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".jpg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".jpeg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
</profiles>
</caching>
<staticContent>
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="text/javascript" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
</staticContent>
<modules>
<clear />
<add name="HttpRedirectionModule" lockItem="false" />
<add name="StaticFileModule" lockItem="false" />
<add name="CustomLoggingModule" lockItem="false" />
<add name="CustomErrorModule" lockItem="false" />
<add name="IsapiModule" lockItem="false" />
<add name="AnonymousAuthenticationModule" lockItem="false" />
</modules>
</system.webServer>
</configuration>
Best Answer
You didn't really say what is failing or provide error messages - but I am going to go out on a limb and take a guess.
My guess is that when you are doing the
<clear />
within modules you are getting a "Lock Violation" error. This is because at the higher level of the IIS7 settings hierarchy, the modules section (and individual modules themselves) are set as locked so that you cannot override/remove them within a web.config file. This is by design, since the modules are really what make up a running IIS system.To be able to do a
<clear />
of modules in web.config, you need to do the following:%windir%\System32\inetsrv\config\applicationHost.config
%windir%\System32\inetsrv\config\applicationHost.config
- you will need to open your editor as an administrator. Also, if you are on 64bit Windows, you will need to use a 64bit editor in order to see the file.<configSections>
area - in thesectionGroup
forsystem.WebServer
- there will be a line that says:<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
Change the
overrideModeDefault
to beAllow
instead ofDeny
.This still won't let you do a
<clear />
in the web.config/modules though, because many of the core modules are locked individually.<modules>
section in applicationHost.config.lockItem
attribute set toTrue
. Change them all to beFalse
.You should now be able to
<clear />
modules in your web.config file.