Creating Static Content Website in IIS 7

In this example we will configure a website in IIS 7 for serving static content as quickly and efficiently as possible. This website is designed to serve files like CSS, JavaScript, Images and HTML. This content is non dynamic, meaning there is no processing or compiling that needs to happen.

The configuration below will give you a result of 100/100 with the Google Page Speed Firefox Plugin.




  
    
  
  
    
    
    
        
        
        
        
        
        
      
    
    
      
      
      
    
    
      
      
      
      
      
      
      
      
      
     
    
        
        
            
                
                
            
        
  


You will get 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:

  • Make a backup copy of %windir%\System32\inetsrv\config\applicationHost.config
  • Open up %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.
  • Find the configSections area – in the sectionGroup for system.WebServer – there will be a line that says:
  • Change the overrideModeDefault to be Allow instead of Deny. This still won’t let you do a clear in the web.config/modules though, because many of the core modules are locked individually.
  • Now look for the modules section in applicationHost.config.
  • Many of the modules listed here have the lockItem attribute set to True.
  • Change them all to be False.
  • Save your applicationHost.config.

You should now be able to clear modules in your web.config file.

This article Deploying a Static Content Server (IIS 7) may also be useful.



Comments

  1. ilker December 29th

    Comment Arrow

    Hello,
    Thanks for your article.
    I have one question and one problem.

    How can I validate request is not passing managed code ?

    And the problem is when I enable that config static compression does not work while I can see the checkbox for static content compress option in iis manager is checked.

    Thanks


  2. ilker December 29th

    Comment Arrow

    And another thing is we should add in section to support cookiless domain.


  3. Kiddailey March 3rd

    Comment Arrow

    Thanks for this. And to save anyone else who might run into this — don’t copy the config from the page here. View the page source and copy it from there. The javascript syntax highlighter removes the camel-casing from the node and attribute names and comments out the XML header, which will cause IIS to complain :)

    I also added to the customHeaders section in mine.


  4. Kiddailey March 3rd

    Comment Arrow

    Er… That was supposed to read: I also added …

    >remove name=”X-Powered-By” /<

    to the customHeaders.


  5. Steve Hankel October 16th

    Comment Arrow

    For IIS 8 you will get an error if you don’t also change lockItem to false in the applicationHost.config:

    name=”CustomLoggingModule” lockItem=”false”


Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Robert

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.