Permission management and working principle of HttpModule

Source: Internet
Author: User

How does httpmodule work?

When an http request arrives at httpmodule, the entire asp tutorial. the. net framework system has not processed this http request. That is to say, httpmodule is the "Only Way" for an http request ", therefore, some required information can be appended to the http request information before the http request is passed to the real request processing center (httphandler, you can also perform some additional work on the intercepted http request information, or simply terminate the http request that meets certain conditions in some cases, so that it can act as a filter.

Using system;
Using system. collections. generic;
Using system. text;
Using system. web;


Namespace myhttpmodule
{
/// <Summary>
/// Description: Used to implement your own httpmodule class.
/// </Summary>
Public class myfirsthttpmodule: ihttpmodule
{
Private void application_beginrequest (object sender, eventargs e)
{
Httpapplication application = (httpapplication) sender;

Httpcontext context = application. context;
Httprequest request = application. request;
Httpresponse response = application. response;

Response. write ("I am from beginrequest in custom httpmodule <br/> ");
}


Private void application_endrequest (object sender, eventargs e)
{
Httpapplication application = (httpapplication) sender;

Httpcontext context = application. context;
Httprequest request = application. request;
Httpresponse response = application. response;

Response. write ("I am from the endrequest in the Custom httpmodule <br/> ");
}

# Region ihttpmodule Member


Public void dispose ()
{
}

 

Public void init (httpapplication application)
{
Application. beginrequest + = new eventhandler (application_beginrequest );
Application. endrequest + = new eventhandler (application_endrequest );
}

# Endregion
}
}

Httpmodule permission management

//// The following content in web. config

 

<Httpmodules>
<Add name = "scriptmodule" type = "system. web. handlers. scriptmodule,
System. web. extensions, version = 3.5.0.0, culture = neutral,
Publickeytoken = 31bf3856ad364e35 "/>
<Add name = "mymodule" type = "mymodule. mymodule"/>
<! -- <Add name = "mymodule" type = ""/> -->
</Httpmodules>
/// This method is called every execution page.

. Net code

 

Using system. configuration;
Using system. linq;
Using system. web;
Using system. web. security;
Using system. web. ui;
Using system.web.ui.html controls;
Using system. web. ui. webcontrols;
Using system. web. ui. webcontrols. webparts;
Using system. xml. linq;

/// <Summary>
/// Summary of class1
Namespace mymodule
{
Public class mymodule: ihttpmodule
{
/// <Summary>
/// Initialize and add two events to the application.
/// </Summary>
/// <Param name = "application"> </param>
Public void init (httpapplication application)
{
Application. beginrequest + = (new
Eventhandler (this. application_beginrequest ));
Application. endrequest + = (new
Eventhandler (this. application_endrequest ));
}
/// Here it must be equivalent to converting response. It cannot be used directly here. I don't know why.
/// Write this statement to determine the permission.
Private void application_beginrequest (object source, eventargs e)
{
Httpapplication application = (httpapplication) source;
Httpresponse responseo tutorial k = application. context. response;




Responseok. write ("
}
Private void application_endrequest (object source, eventargs e)
{
Httpapplication application = (httpapplication) source;
Httpresponse responseok = application. context. response;
Responseok. write ("}
Public void dispose (){}
}
}

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.