asp: A concrete way to write ashx into a class library and invoke it on a page

Source: Internet
Author: User

Building an HTTP handler in a class library is simple, adding an ordinary class, and then pasting the code in the previous ashx almost exactly as it is in this class. But pay attention to namespaces and class names, because we'll use them later.
Sample handler:

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 to implement: IsReusable and ProcessRequest the members defined in both interfaces.
Below we will go to the site's web. config to register this handler. If you are using IIS7 and above, and use the integrated mode, it is necessary to configure:
Under the System.webserver\handlers node, add:
<add name= "Examplehandler" verb= "*" path= "Ex.axd" type= "EdiBlog.Core.Web.HttpHandlers.ExampleHandler, Ediblog.core "/>

Where path is the path to access handler, and the extension needs to be registered in IIS, if you are using a virtual host like me, and you cannot manage IIS yourself, do not use an extension name that is not supported by IIS, such as ABC.
The 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 access the handler on the webpage!

asp: A concrete way to write ashx into a class library and invoke it on a page

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.