Processing of multiple httpmodules in HTTP module and ASP. NET

Source: Internet
Author: User

Using System;
Using System. Web;

Namespace Xumh
{
///   <Summary>
/// Application Example of multiple httpmodules:
/// In the httpmodules file of the web. config file, execute the httpmodules command in the order of ADD.
/// Events to be filtered by multiple httpmodules are processed separately.
///   </Summary>
Public   Class Multihttpmodule: ihttpmodule
{
Public   Void Dispose ()
{
Throw   New Notimplementedexception ();
}

Public   Void Init (httpapplication context)
{
// Redefinition of ASP. NET event processingProgram
Context. beginrequest + =   New Eventhandler (mybeginrequest );
Context. endrequest
+ =   New Eventhandler (myendrequest );
Context. prerequesthandlerexecute
+ =   New Eventhandler (myprerequesthandlerexecute );
Context. postrequesthandlerexecute
+ =   New Eventhandler (mypostrequesthandlerexecute );
Context. releaserequeststate
+ =   New Eventhandler (myreleaserequeststate );
Context. acquirerequeststate
+ =   New Eventhandler (myacquirerequeststate );
Context. authenticaterequest
+ =   New Eventhandler (myauthenticaterequest );
Context. authorizerequest
+ =   New Eventhandler (myauthorizerequest );
Context. resolverequestcache
+ =   New Eventhandler (myresolverequestcache );
Context. presendrequestheaders
+ =   New Eventhandler (mypresendrequestheaders );
Context. presendrequestcontent
+ =   New Eventhandler (mypresendrequestcontent );

}

Void Mypresendrequestcontent ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Mypresendrequestcontent <br/> " );
}

Void Mypresendrequestheaders ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Mypresendrequestheaders <br/> " );
}

Void Myresolverequestcache ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Myresolverequestcache <br/> " );
}

Void Myauthorizerequest ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Beginrequest <br/> " );
}

Void Myauthenticaterequest ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Beginrequest <br/> " );
}

Void Myacquirerequeststate ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Myacquirerequeststate <br/> " );
}

Void Myreleaserequeststate ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Myreleaserequeststate <br/> " );
}

Void Mypostrequesthandlerexecute ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Mypostrequesthandlerexecute <br/> " );
}

Void Myprerequesthandlerexecute ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Myprerequesthandlerexecute <br/> " );
}

Void Myendrequest ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Myendrequest <br/> " );
}

Void Mybeginrequest ( Object Sender, eventargs E)
{
Httpapplication app
= (Httpapplication) sender;
Httpcontext Context
= App. context;
Context. response. Write (
" Multihttpmodules: mybeginrequest <br/> " );
}

}
}
/*-- ===-------------------------------------------- = ---
Output result:
Testhttpmodule: mybeginrequest
Multihttpmodules: mybeginrequest
Beginrequest
Beginrequest
Myresolverequestcache
Myacquirerequeststate
Myprerequesthandlerexecute


mypostrequesthandlerexecute
myreleaserequeststate
myendrequest
mypresendrequestheaders
-- ====--- */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.