Another day of Dan's pain !!
What to do, customize something. Let's take httpmodule and httphandler to get started!
I. Custom httpmodule
The custom httpmodule needs to implement the ihttpmodule interface. The two methods in the interface need to be implemented in the inheritance class, the init and dispose methods; The init method has a parameter httpapplication, we can get some attributes or customize some processing for this parameter.Program, What can be dug in httpapplication, this can be seen by yourself to implement the following; because I am doing the demo, so the init method registered the beginrequest processing program,CodeAs follows:
Public void Init (httpapplication application) {application. beginrequest + = new eventhandler (application_beginrequest );}
Void application_beginrequest (Object sender, eventargs e) {httpcontext context = (sender as httpapplication). Context; context. response. Write ("custom configuration successful ");}
After writing the program, you need to configure it in Web. config. The configuration is very simple.
<Httpmodules> <Add name = "myhttpmodule" type = "myhttpmodule. myhttpmodule, webapplication1"/>
Note that the parameter type = "myhttpmodule. myhttpmodule, webapplication1" is: namespace + processing class, assembly; sometimes the namespace and assembly are different.
Ii. Custom httphandler
Same as above: the ihttphandler interface must be inherited to implement the methods in the interface: processrequest and attributes: isreusable (whether the flag is cached)
Code:
Public class myhandler: ihttphandler {public void processrequest (httpcontext context) {context. response. write ("<br/> Hello World");} public bool isreusable {get {return false ;}}}
You also need to configure in Web. config
<Httphandlers> <add verb = "*" type = "webapplication1.myhandler, webapplication1" Path = "*. aspx"/>
Specific parameters: verb-submit method: Post, get .... * All; Type: namespace + handler class, assembly name; Path: file to be processed (you can customize the type, such :. myfoot, but it needs to be configured in IIS. The basic aspx will not be used)
In fact, the Code shows that the init method parameter of myhttpmodule is httpapplication, while the parameter of myhandler method processrequest is httpcontext. It can be concluded that myhttpmodule occurred before myhandler, therefore, you must write the required functions in the correct processing program.
Okay, it's time to get off work at. Hope you can beat it !!