asp.net: Practical tips for writing ashx to class libraries and calling them on the page

Source: Internet
Author: User

The simple way to build an HTTP handler in a class library is to add an ordinary class, and then paste the code from the previous ashx almost exactly the same into the class. But be aware of namespaces and class names, because we'll use them later.
Sample handler:

Copy Code code as follows:

Namespace EdiBlog.Core.Web.HttpHandlers
{
Using System;
Using System.Web;

public class Examplehandler:ihttphandler
{
public bool IsReusable
{
get {return false;}
}

public void ProcessRequest (HttpContext context)
{
Your own logic ...
}
}
}


The logic of this handler is not important, you can define it yourself. The key point is implementation: IsReusable and ProcessRequest the members defined in these two interfaces.
Below we will go to the site's Web.config to register this handler. If you are using IIS7 and the above version, and the integration mode, you need to configure this:
Add under the System.webserver\handlers node:
<add name= "Examplehandler" verb= "path=" Ex.axd "type=" EdiBlog.Core.Web.HttpHandlers.ExampleHandler, Ediblog.core "/>

Where path is access to handler, and the extension needs to be registered in IIS, and if you are using a virtual host like me, and you cannot manage IIS yourself, do not use the extension name that IIS does not support by default, such as ABC.
Type has two parameters, the first is the full name of the handler class, and the second is the name of the assembly.
Now we can use Ex.axd to visit handler on the website!

Related Article

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.