1.ihttpModule(粘合剂,侦听application事件或用户自定义事件。) 2.ihttpHandler(可以自定义对特定资源进行处理) 2.ihttpHandlerFactory(可以用来进行在自定义ihttpmodule或标准的ihttpModule之间进行选择)
ihttpHandler拦截httpRequest. ihttpModule是事件侦听器(其作用跟glob.aspx有些相同) 区别: ihttpHandler 完全负责页面的请求和响应 ihttpModule 负责在其Init事件中申请的HttpApplication事件,执行完还要按HttpApplication其他事件执行 应用程序按照以下顺序执行由 global.asax 文件中定义的模块或用户代码处理的事件: 在 PostResolveRequestCache 事件之后、PostMapRequestHandler 事件之前创建一个事件处理程序(对应于请求 URL 的页)。 8.PostMapRequestHandler 执行事件处理程序。 在 PostReleaseRequestState 事件之后,响应筛选器(如果有)将对输出进行筛选。 17.EndRequest 默认的一些事件的处理ihttpmodule <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> 具体使用方法: using
System.Web; 然后生成dll,新建个asp.net应用,引用此dll,在web.config中加入 <httpModules> 则当有页面请求时会查找到此dll,然后执行其中过程。 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 以下为重写IHttpHandler中方法的代码: 同样地建个类库 using
System; 所有页面请示的核心处理都是通过IHttpHandler的ProcessRequest方法来完成,因此只要我们重写此方法,则无论页面有任何请求,都会被我们所重写的内容代替掉。嘿嘿 生成dll后再在asp.net应用中的 web.config 中加入 <httpHandlers> |