Microsoft KB Archive/930909

= How to use the Appcmd.exe command-line tool to enable and configure HTTP logging and other features in Internet Information Services 7.0 =

Article ID: 930909

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Internet Information Services 7.0

-



INTRODUCTION
The following features cannot be configured by using the Microsoft Internet Information Services (IIS) 7.0 Manager:
 * HTTP logging
 * HTTP redirection
 * HTTP response headers
 * HTTP compression

To enable and configure these features, you must use the Appcmd.exe command-line tool instead.



MORE INFORMATION
To enable these features in IIS 7.0, use the Appcmd.exe command-line tool. When you use this tool, you must first enable the feature. Then, you must configure the settings for the feature. When you run the Appcmd.exe tool, settings are updated in the %windir%\System32\Inetsrv\Config\ApplicationHost.config file.

The following sections describe how to use the Appcmd.exe tool to enable various HTTP features in IIS 7.0. To determine other IIS attributes and settings that you can change by using the Appcmd.exe tool, view the full schema in the %windir%\System32\Inetsrv\Config\Schema\IIS_schema.xml file.

HTTP logging
To enable logging for HTTP requests, follow these steps:  Click Start, type command prompt in the Start Search box, right-click Command Prompt in the Programs list, and then click Run as administrator.

If you are prompted for an administrator password or for confirmation, type your password, or click Continue. Type the following command, and then press ENTER:

cd \windows\system32\inetsrv

 Type the following command, and then press ENTER:

appcmd set config /section:httpLogging /dontLog:False /selectiveLogging:LogAll

Note This command configures HTTP logging to use the default logging settings from the schema file for all Web sites that are configured on the Web server. The selectiveLogging attribute can equal one of the following values:  LogError

This value specifies that all errors are logged. LogSuccessful

This value specifies that all successful requests are logged. LogAll

This value specifies that all requests are logged. </li></ol>

To disable logging for HTTP requests, type the following command, and then press ENTER:

appcmd set config /section:httpLogging /dontLog:True

Additional logging options
After you have enabled logging for HTTP requests, you can set additional logging options. For example, you can set specific information to log. The following command demonstrates how to log only HTTP substatus information for all Web sites:

appcmd set config /section:sites -siteDefaults.logFile.logExtFileFlags:HttpSubStatus

You can log the following information for the Web site that has an ID value of 1:
 * HTTP substatus
 * Host
 * Time
 * Date

To do this, use a command that resembles the following:

appcmd set config /section:sites /[id='1'].logFile.logExtFileFlags:HttpSubStatus,Host,Time,Date

HTTP redirection
To enable HTTP redirection, follow these steps: <ol> Click Start, type command prompt in the Start Search box, right-click Command Prompt in the Programs list, and then click Run as administrator.

If you are prompted for an administrator password or for confirmation, type your password, or click Continue.</li> Type the following command, and then press ENTER:

cd \windows\system32\inetsrv

</li> Type the following command, and then press ENTER:

appcmd set config /section:httpRedirect /enabled:true

</li></ol>

To add an HTTP redirection rule, type the following command, and then press ENTER:

appcmd set config /section:httpRedirect/+[wildcard=' ',destination=' ']

Note In this command,  represents the Web page or pages that you want to redirect. represents the destination Web page to which the  value redirects.

To disable HTTP redirection, type the following command, and then press ENTER:

appcmd set config /section:httpRedirect /enabled:false

HTTP response headers
To add an HTTP response header, follow these steps: <ol> Click Start, type command prompt in the Start Search box, right-click Command Prompt in the Programs list, and then click Run as administrator.

If you are prompted for an administrator password or for confirmation, type your password, or click Continue.</li> Type the following command, and then press ENTER:

cd \windows\system32\inetsrv

</li> Type the following command, and then press ENTER:

appcmd set config /section:httpProtocol /+customHeaders.[name=' ',value=' ']

Note In this command,  represents the name of the HTTP header that you are adding. represents the value of the HTTP header that you are adding.</li></ol>

To edit an HTTP response header, type the following command, and then press ENTER:

appcmd set config /section:httpProtocol /customHeaders.[name=' ']. value:

Note In this command,  represents the name of the HTTP header that you want to edit. represents the value of the HTTP header that you are editing.

To view a list of HTTP response headers, type the following command, and then press ENTER:

appcmd list config /section:httpProtocol

HTTP compression
To enable HTTP compression, follow these steps: <ol> Click Start, type command prompt in the Start Search box, right-click Command Prompt in the Programs list, and then click Run as administrator.

If you are prompted for an administrator password or for confirmation, type your password, or click Continue.</li> Type the following command, and then press ENTER:

cd \windows\system32\inetsrv

</li> Enable static content compression or dynamic content compression. To do this, use one of the following methods:  To enable static content compression, type the following command, and then press ENTER:

appcmd set config /section:urlCompression /doStaticCompression:True

</li> To enable dynamic content compression, type the following command, and then press ENTER:

appcmd set config /section:urlCompression /doDynamicCompression:True

</li></ul> </li></ol>

<div class="references_section">