Responsibility chain model learning

Source: Internet
Author: User

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.

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.