Share via


Configure Settings for a Site, Application, Virtual Directory, or URL by Using Appcmd.exe (IIS 7)

Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista

In IIS 7, you can configure settings in server-level configuration files or in Web.config files for a site, application, or virtual directory on your Web server. Users who view or change settings in Web.config files in site or application directories must have read and write access to files in those directories. Additionally, you must delegate features that you want to configure at the site, application, or virtual directory level in IIS 7. For more information about configuration files and delegating features, see Working With Configuration Files in IIS 7 and Delegate Site and Application Management (IIS 7).

Use Appcmd.exe to Change Configuration in a Web.config file

When you use Appcmd.exe to configure settings in a Web.config file for a specific site, application, or virtual directory, you must specify the path of the site, application, or virtual directory for which you want the configuration to apply. For example, to disable the default document feature for a Web site named Contoso, type the following command at the command prompt, and then press ENTER:

appcmd set config "Contoso" /section:defaultDocument /enabled:false

In the previous example, the configuration changes are made in the Web.config file in the Contoso directory, and all the Contoso applications and virtual directories inherit the configuration from that Web.config file. However, if you want to enable default documents for a specific application in the Contoso site, you can use Appcmd.exe to provide the path of the application. For example, to enable default documents for an application named Gallery, type the following command at the command prompt, and then press ENTER:

appcmd set config "Contoso/Gallery" /section:defaultDocument /enabled:true

The command in the previous example enables default documents for the Gallery application in the Contoso site, and writes the configuration changes to the Web.config file in Gallery's directory.

Use Appcmd.exe to Change Configuration in a Parent-Level Configuration File

The previous section explained how to use Appcmd.exe to configure features for a specific site, application, or virtual directory by writing changes to a Web.config file. You can also configure features for a specific site, an application, a virtual directory, or even a URL by using location tags in a parent configuration file.

When you want to configure settings for a site, application, or virtual directory but you want to store the settings in a parent configuration file, such as in ApplicationHost.config instead of in a Web.config file, you must use the Appcmd.exe commit parameter with your command. By using the examples in the previous section, you can now write the configuration changes to ApplicationHost.config instead of to the site and application Web.config files.

First, to disable default documents for the Web site named Contoso, type the following command at the command prompt, and then press ENTER:

appcmd set config "Contoso" /section:defaultDocument /enabled:false /commit:APPHOST

The previous command disables default documents for the Contoso site, and writes the configuration settings with a location tag to ApplicationHost.config. The location tag specifies that the configuration applies to the Contoso site. The configuration section resembles the following example:

<location path="Contoso">
      <system.webServer>
            <defaultDocument enabled="false" />
      </system.webServer>
</location>

Second, to enable default documents for the application named Gallery, type the following command at the command prompt, and then press ENTER:

appcmd set config "Contoso/Gallery" /section:defaultDocument /enabled:true /commit:APPHOST

The previous command enables default documents for the Gallery application, and writes the configuration settings with a location tag to ApplicationHost.config. The location tag specifies that the configuration applies to the Gallery application. The configuration section looks like the following example:

<location path="Contoso/Gallery">
      <system.webServer>
            <defaultDocument enabled="true" />
      </system.webServer>
</location>

See Also

Concepts

Appcmd.exe (IIS 7)