I saw an article written by a friend in the blog, entitled "ihttphandler" and "responsibility chain". This friend's article is good, that is, the layout is poor, and it looks a little hard, by the way, I sorted out the code of this friend.
Summary:
Hellohandler. CS, handlersectionelement. CS, handlersectioncollection. CS, handlersection. CS, handlerconfig. CS is used to access the Web. the configuration section in config is created. for the specific implementation of these classes, refer to the source code and examples provided.
Code
<Configsections>
<Section name = "chainhandlersection" type = "handlerexample. handlersection, handlerexample" allowdefinition = "everywhere" allowlocation = "false"/>
</Configsections>
<Chainhandlersection>
<Handlers>
<! -- The value of type can be different processing classes in different assemblies,
The processing class configured here is to process the types received by httphandlers,
For example, the httphandlers configuration section receives two types of aspx and ashx
Ashx has hellohandler for processing,
Aspx has no corresponding processing program, and the result system has an error,
Throw new notimplementedexception ("unknown handler ").
-->
<Add type = "handlerexample. hellohandler, handlerexample"/>
<! -- <Add type = "handlerexample. worldhandler, handlerexample"/> -->
</Handlers>
</Chainhandlersection>
<Appsettings/>
<Connectionstrings/>
<System. Web>
<Httphandlers>
<Add verb = "*" Path = "*. ashx" type = "handlerexample. chainhandlerfactory, handlerexample"/>
<Add verb = "*" Path = "*. aspx" type = "handlerexample. chainhandlerfactory, handlerexample"/>
</Httphandlers>
The chainhandler class implements the ihttphandler interface. Its derived class is used to process the type received by chainhandlerfactory. chainhandlerfactory can concatenate classes derived from chainhandler into strings.
That is, forming a chain in the responsibility chain model.
In the source code and example, set handler. ashx and default. aspx In the example to the start page respectively to see the effect.