How to: Configure <system.webServer> section 2008-06-14 for IIS 7.0 22:26http://technet.microsoft.com/zh-cn/sysinternals/bb763179.aspx
How to: Configure <system.webServer> section for IIS 7.0
The system.webserver section in the Web.config file specifies the IIS 7.0 settings that apply to the WEB application. System. WebServer is a child of the configuration section. For more information, see IIS 7.0:system.webserver section group (IIS Settings Schema) (IIS 7.0:system.webserver node groups (IIS Setup schemas)).
The following are available in system. Examples of Web server settings in the WebServer configuration group:
When a request does not contain a specific resource, the WEB server returns the default document (defaultdocument element) to the client.
The compression setting for the response (httpcompression element).
The custom header (the customheaders element of the Httpprotocol section).
Module (modules Element).
Handler (handlers Element).
Some of the settings in the System.webserver section apply only to IIS 7 set mode and not to Classic mode. Specifically, if the application is running in Classic mode, the system of the Web.config file is ignored. All managed code modules and handlers specified in the WebServer section. As with earlier versions of IIS, managed code modules and handlers must be defined in the httpmodules and httphandlers elements of the system.web section.
This topic illustrates three common configuration tasks that need to be modified for the system.webserver section:
Add a default file to provide the default file when the request URL does not contain a specific file.
Registers a managed code module.
Add custom response headers.
Configure a default file IIS 7.0 provides a default file when the request URL does not contain a specific file for the Web application.
Configure Default Files
If your application does not have a Web.config file, use Visual Studio or a text editor to create the file.
For more information, see Editing asp.net configuration files.
If the Web.config file does not already contain the system.webserver section, create the section in the configuration element, as shown in the following example:
Copy Code
<configuration>
<system.webServer>
</system.webServer>
</configuration>
Within the system.webserver element, create a defaultdocument element.
Within the defaultdocument element, create a files element.
Creates an add element within the files element and specifies the path and name of the default file within the Value property.
The following example demonstrates a system.webserver section that is configured to provide products.aspx files as the default file.
Copy Code
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value= "Products.aspx"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
Registering a managed code module invokes the managed-code module on each request, which allows you to customize the request or response.
Configuring custom managed code Modules
If your application does not have a Web.config file, use Visual Studio or a text editor to create the file.
For more information, see Editing asp.net configuration files.
If the Web.config file does not already contain the system.webserver section, create the section in the configuration element, as shown in the following example:
Copy Code
<configuration>
<system.webServer>
</system.webServer>
</configuration>
Within the system.webserver element, create a modules element.
Creates an add element within the modules element and specifies the custom module in the name and type attribute.
The actual name and type depend on the module you want to add. The following example shows how to add a custom module named CustomModule, which is implemented as a type samples.custommodule.
Copy Code
<configuration>
<system.webServer>
<modules>
<add name= "CustomModule" type= "Samples.custommodule"/>
</modules>
</system.webServer>
</configuration>
Add the Precondition property to the module registration and set its value to Managedhandler.
The predecessor condition causes the module to be invoked only if the ASP.net application resource, such as an. aspx file or managed handler, is requested. static files (for example,. htm files) are not included in this resource.
Its configuration section will resemble the following example.
Copy Code
<configuration>
<system.webServer>
<modules>
<add name= "CustomModule" type= "Samples.custommodule"
precondition= "Managedhandler"/>
</modules>
<defaultDocument>
<files>
<add value= "Products.aspx"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
Configure a custom response header using a custom response header, you can send application-specific information to the browser. For example, you can add a content-language header to describe the language used in the body of a Web page. To do this, provide one or more languages and country/region values, such as en-us (U.S. English) or EN-GB (British English).
Configuring Custom Response Headers
If your application does not have a Web.config file, use Visual Studio or a text editor to create the file.
For more information, see Editing asp.net configuration files.
If the Web.config file does not already contain the system.webserver section, create the section in the configuration element, as shown in the following example:
Copy Code
<configuration>
<system.webServer>
</system.webServer>
</configuration>
Within the system.webserver element, create a HTTPPROTOCOL element.
Within the Httpprotocol element, create a customheaders element.
Creates an add tag within the customheaders element and specifies the custom header in the name and Value property.
The actual name and type will depend on the functionality of the header in the application. The following example shows how to add a custom header named Customheader with a value of Customheader.
Copy Code
<configuration>
<system.webServer>
<customHeaders>
<add name= "Customheader" value= "Customheader"/>
<customHeaders>
</system.webServer>
</configuration>
[This log is edited by Simon 2011-06-12 09:20 AM)
Article from: the original site