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 stanza groups (IIS provisioning Schema)).
The following are available on the system. Example of Web server settings that are made in the WebServer configuration group:
-
defaultdocument elements).
-
response compression settings (httpcompression Element).
-
httpprotocol section customheaders element).
-
module (modules element).
-
handler (handlers element).
some of the settings in the System.webserver section apply only to IIS 7 Integrated mode, 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 the three common configuration tasks that you need to modify the system.webserver section:
Add a default file so that when the request URL does not contain a specific file, the default file is provided.
Registers a managed code module.
Add a custom response header.
Configure default Files
When the request URL does not contain a specific file for the Web application, IIS 7.0 provides a default file.
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 an ASP. NET configuration file.
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:
< Configuration > < system.webserver > </ system.webserver > </ Configuration >
within the system.webserver element, create a defaultdocument element.
within the defaultdocument element, create a files element.
Create an add element within the files element and specify the path and name of the default file within the Value property.
The following example shows a system.webserver section that is configured to provide a products.aspx file as the default file.
<Configuration> <system.webserver> <defaultdocument> <Files> <Addvalue= "Products.aspx" /> </Files> </defaultdocument> </system.webserver></Configuration>
registering a managed code module
The managed code module is invoked each time the request is made 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 an ASP. NET configuration file.
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:
< Configuration > < system.webserver > </ system.webserver > </ Configuration >
within the system.webserver element, create a modules element.
Create an add element within the Modules element and specify the custom module in the name and type properties.
The actual name and type depend on the module you are adding. The following example shows how to add a custom module named CustomModule, which will be implemented as type samples.custommodule.
<Configuration> <system.webserver> <Modules> <Addname= "CustomModule"type= "Samples.custommodule" /> </Modules> </system.webserver></Configuration>
Add the Precondition property to the module registration and set its value to Managedhandler.
A preceding condition causes the module to be called only when an ASP. NET application resource, such as an. aspx file or managed handler, is requested. Static files, such as. htm files, are not included in the resource.
Its configuration section will resemble the following example.
<Configuration> <system.webserver> <Modules> <Addname= "CustomModule"type= "Samples.custommodule"Precondition= "Managedhandler" /> </Modules> <defaultdocument> <Files> <Addvalue= "Products.aspx" /> </Files> </defaultdocument> </system.webserver></Configuration>
Configure custom Response headers with custom response headers, you can send application-specific information to your browser. For example, you can add a content-language header to describe the language used in the body of the Web page. To do this, provide one or more language and country/region values, such as en-us (U.S. English) or EN-GB (UK English). Configure 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 an ASP. NET configuration file.
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:
< Configuration > < system.webserver > </ system.webserver > </ Configuration >
within the system.webserver element, create a httpprotocol element.
within the Httpprotocol element, create a customheaders element.
Create an Add tag within the Customheaders element and specify a custom header in the name and value properties.
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.
<Configuration> <system.webserver> <Httpprotocol> <customheaders> <Addname= "Customheader"value= "Customheader" /> <customheaders> </Httpprotocol> </system.webserver></Configuration>
Configuring for IIS 7.0 <system.webServer>