The IIS 7 configuration system contains 50+ configuration sections (100+ if you count .NET Framework configuration), 477 attributes, and 57 collections. This can make it pretty challenging to figure out exactly what IIS 7 configuration section needs to be used to turn on some particular behavior, and then exactly syntax the configuration in that section should follow.
The IIS Manager tool removes some of this complexity by surfacing task-based UI to set IIS 7 configuration for many features, and can be used to do most common configuration tasks very easily. However, it sometimes isn't enough – it doesn't cover all configuration sections in IIS 7, and cant be used from a script to do automated deployment or configuration.
A lot of the time, I remember enough to write most IIS configuration from memory. But, what if you didn't spend the past 4 years developing IIS7? 🙂
Thankfully, there are a few things you can do to make this process a lot simpler:
1) Use AppCmd to dump all of the configuration sections you can set
NOTE: Be sure to run AppCmd.exe from a command line prompt running as Administrator, when logged in using an account with Administrative privileges
> %windir%system32inetsrvappcmd set config /section:?
This dumps a list of all configuration sections you can set, and looks something like this:
You can scan the list of sections to spot something that may look interesting to you. If you want to narrow it down, you can use an undocumented trick to search for sections using wildcard search expression (if you are not comfortable with findstr.exe or a haven't yet developed your own version of grep):
> %windir%system32inetsrvappcmd set config "/section:?system.webServer/*" to find all sections that start with "system.webServer/" (runtime IIS configuration sections)
Yes, it's a dirty hack, but its damn useful when you are looking for stuff you know is there. Now, where was that tracing configuration? Search for *trac*:
> %windir%system32inetsrvappcmd set config "/section:?*trac*"
2) AHA! Found the section. Now, how do I set the damn settings?
Use AppCmd to dump all the attributes, elements, and collections you can set on the section:
> %windir%system32inetsrvappcmd set config /section:system.webServer/httpErrors /?
This shows you all you need to know to set configuration with AppCmd. The  syntax indicates collections – you need to specify the collection keys inside the brackets to identify specific elements you want to touch, and the attributes you can set on those elements. For example, to add a new error code to that collection, we could do:
> %windir%system32inetsrvappcmd set config /section:system.webServer/httpErrors /+[statusCode='505',subStatusCode='0',path='c:503.html']
Likewise, to edit this element later:
> %windir%system32inetsrvappcmd set config /section:system.webServer/httpErrors /[statusCode='505',subStatusCode='0'].path='c:503_v2.html'
The cool thing is that you can use the same syntax to see what properties you can set on sites, applications, virtual directories and application pools. Just try:
> %windir%system32inetsrvappcmd set site "Default Web Site" /?
> %windir%system32inetsrvappcmd set app "Default Web Site/" /?
> %windir%system32inetsrvappcmd set vdir "Default Web Site/" /?
> %windir%system32inetsrvappcmd set apppool "DefaultAppPool" /?
Now you should be able to poke around the configuration system on your own and figure out the syntax for setting configuration without getting completely confused. If you want more, you can dive deeper into the schema of configuration, by looking at the IIS configuration schema. These files are located in %windir%system32inetsrvconfigschema, and will tell you everything there is to know about IIS (and .NET Framework and ASP.NET v2.0) configuration sections:
Directory of C:Windowssystem32inetsrvconfigschema
10/25/2007 12:30 PM <DIR> .
10/25/2007 12:30 PM <DIR> ..
09/17/2007 02:38 AM 38,786 ASPNET_schema.xml
09/17/2007 02:38 AM 26,971 FX_schema.xml
09/17/2007 02:38 AM 74,797 IIS_schema.xml
09/13/2007 01:13 PM 1,244 responsefilter_schema.xml
09/17/2007 02:38 AM 8,363 rscaext.xml
5 File(s) 150,161 bytes
2 Dir(s) 9,947,492,352 bytes free
Related resources for you:
Creating IIS7 sites, applications, and virtual directories
Anatomy of an IIS7 configuration path
IISSCHEMA.EXE – A tool to register IIS7 configuration sections
IIS.NET – Article – Getting Started with AppCmd.exe
IIS.NET – Article – Deep Dive into IIS7 Configuration