How to used HttpModule
2006-04-30 17:34
295 查看
HttpModulesallowyoutoextendtheexistingASP.NETpipeline.ThemostcommonuseofHTTPModulesispreand/orepostprecessingofrequests.InternallyASP.NETutilizescustommodules(httpmodules)for:outputcaching,authenticationandauthorizationetc.Therefore,ifyoueverneedtotapintothepiplelinetoaltertherequestinanyway,lookintoHttpModulesastheyprovidearelativelyeasywayforyoutodojustthat(similiartohowISAPIfiltershelpedachievepre/postprocessingcapabilities).
TodevelopanHttpModuleyouarerequiredtodothefollowing:
YouclassmustimplementtheiHttpModuleInterface
BoththeInit(..)andDispose()methodsmustbeinyourclassdefinitions
Belowisasimpleexamplethatoutputs"HttpModulesaysHello!"toeachandeveryrequest.YouwillnoticethatIwiredaneventintheInit(..)methodthatcallsOnBeginRequestatthebeginningofeveryrequest.
[/code]
[/code]
TodevelopanHttpModuleyouarerequiredtodothefollowing:
YouclassmustimplementtheiHttpModuleInterface
BoththeInit(..)andDispose()methodsmustbeinyourclassdefinitions
Belowisasimpleexamplethatoutputs"HttpModulesaysHello!"toeachandeveryrequest.YouwillnoticethatIwiredaneventintheInit(..)methodthatcallsOnBeginRequestatthebeginningofeveryrequest.
usingSystem; usingSystem.Web; namespaceCSharpFriends.Samples { publicclassCSharpFriendsHttpModule:IHttpModule { publicCSharpFriendsHttpModule() { [code]} /// ///RequiredbytheinterfaceIHttpModule /// publicvoidDispose() { } /// ///RequiredbytheinterfaceIHttpModule ///IalsowireuptheBeginRequestevent. /// publicvoidInit(System.Web.HttpApplicationApp) { App.BeginRequest+=newSystem.EventHandler(OnBeginRequest); App.EndRequest+=newSystem.Eventhandler(OnEndRequest); } [/code]
|
Inyourweb.config,addthefollowingelements:
<httpModules>
<addtype="CSharpFriends.Samples.CSharpFriendsHttpModule,Test"name="CSharpFriendsHttpModule"/></httpModules>
[/code]
[/code]
相关文章推荐
- how to write a nginx module for http living stream
- HTTP cookies, or how not to design protocols
- 表中真正使用的空间(How to Determine Real Space used by a Table (Below the High Water Mark)
- How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable. [reprint]
- HOW TO FIX No module named pywintypes
- nginx-sticky-module-1.1//ngx_http_sticky_misc.c:281:2: error: too few arguments to function
- [Environment Config]How to fix “ImportError: No module named scapy.all”
- How to deal with "Incorrect NSStringEncoding value 0×0000 Error with ASIHTTPRequest" problem?
- [转]How to identify the template used to create a site..
- Java Tutorial: How to Create RESTful Java Client using Apache HttpClient – Example
- 如何关闭Golang中的HTTP连接 How to Close Golang's HTTP connection
- How to handle the session in HttpClient 4.1
- How to use HttpSendRequestEx with password-protected URLs
- How to use HttpURLConnection POST data to web server?
- How to use Fiddler and HTTP replay to have an offline copy of your site
- How to enable wire logging for a java HttpURLConnection traffic?
- How to log application API calls using import module addresses
- How to Send an HTTP Header With Every Request With Spring RestTemplate
- How is jstack being used to find the bottlenect of a java program
- FFmpeg codec HOWTO(http://wiki.multimedia.cx/index.php?title=FFmpeg_codec_HOWTO)