httpModules 元素(ASP.NET 设置架构)

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

在一个应用程序内配置 HTTP 模块。 可以在配置层次中的任何级别声明此元素。

<httpModules> 
   <add... />
   <remove... />
   <clear/>
</httpModules>

特性和元素

以下几节描述了特性、子元素和父元素。

特性

无。

子元素

元素

说明

add

可选元素。

向应用程序添加 httpModules 元素。

clear

可选元素。

从应用程序中移除所有的 httpModules 元素。

remove

可选元素。

移除对 httpModules 元素的引用。

该值必须与上一个 add 指令的值完全匹配。

父元素

元素

说明

configuration

指定公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。

system.web

为 ASP.NET 配置节指定根元素。

备注

默认配置

下面的默认 httpModules 元素在 .NET Framework 1.1 版的 Machine.config 文件中配置。

<httpModules>
     <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
     <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
     <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/>
     <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/>
     <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule"/>
     <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/>
     <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/>
     <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, 
          Version=1.0.5000.0, Culture=neutral, 
          PublicKeyToken=b03f5f7f11d50a3a"/>
</httpModules>

下面的默认 httpModules 元素在 .NET Framework 1.0 版的 Machine.config 文件中配置。

<httpModules>
     <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
     <add name="Session" type="System.Web.SessionState.SessionStateModule" />
     <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
     <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
     <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
     <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
     <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
</httpModules>

下面的默认 httpModules 元素在 .NET Framework 版本 2.0 的根 Web.config 文件中配置。

<httpModules>
     <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
     <add name="Session" type="System.Web.SessionState.SessionStateModule" />
     <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
     <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
     <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
     <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
     <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
     <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
     <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
     <add name="Profile" type="System.Web.Profile.ProfileModule" />
</httpModules>

示例

下面的代码示例演示如何添加三个对 ASP.NET 应用程序的 HttpModule引用。

<configuration>
   <system.web>
      <httpModules>
         <add type="System.Web.Caching.OutputCacheModule" 
              name="OutputCache"/>
         <add type="System.Web.SessionState.SessionStateModule" 
              name="Session"/>
         <add type=Selector, selector.dll"
              name="Selector"/>
      </httpModules>
   </system.web>
</configuration>

元素信息

配置节处理程序

System.Web.Configuration.HttpModulesSection

配置成员

SystemWebSectionGroup.HttpModules

可配置的位置

Machine.config

根级别的 Web.config

应用程序级别的 Web.config

虚拟或物理目录级别的 Web.config

要求

Microsoft Internet 信息服务 (IIS) 版本 5.0、5.1 或 6.0

.NET Framework 版本 1.0、1.1 或 2.0

Microsoft Visual Studio 2003 或 Visual Studio 2005

请参见

任务

How to: Lock ASP.NET Configuration Settings

参考

system.web 元素(ASP.NET 设置架构)

<configuration> 元素

httpModules 的 add 元素(ASP.NET 设置架构)

httpModules 的 clear 元素(ASP.NET 设置架构)

httpModules 的 remove 元素(ASP.NET 设置架构)

System.Configuration

System.Web.Configuration

概念

ASP.NET Configuration Overview

ASP.NET Server Controls and Browser Capabilities

Securing Configuration

Configuration Inheritance

其他资源

ASP.NET Configuration Files

ASP.NET 配置设置

常规配置设置 (ASP.NET)

ASP.NET Configuration API