天天看點

關于HttpModule事件順序和執行順序

關于HttpModule事件順序和執行順序

總的來說,有如下事件會依次觸發。

beginrequest

authenticaterequest

authorizerequest

resolverequestcache

acquirerequeststate

prerequesthandlerexecute

postrequesthandlerexecute

releaserequeststate

updaterequestcache

endrequest

此外,有三個不确定的順序:

presendrequestheaders

presendrequestcontent

error

那麼,當我們注冊了多個module之後會怎麼樣呢?

舉個例子:

如果你在web.config配置了兩個httpmodule,分别是httpmodulea,httpmoduleb

這個事件執行的順序如下:

httpmodulea->beginrequest

httpmoduleb->beginrequest

httpmodulea->authenticaterequest

httpmoduleb->authenticaterequest

httpmodulea->authorizerequest

httpmoduleb->authorizerequest

...以此類推  

當然了,系統預設的那些module總是在自定義module之前執行

framework中預設的module(c:\windows\microsoft.net\framework\v2.0.50727\config\web.config)