ASP. NET: How to Write ashx to the class library and call it on the page

Source: Internet
Author: User

Recently, the blog architecture has been adjusted to further separate the performance from the business. Therefore, we need to put the Http Handler previously used in ashx into the class library. The Http Handler creation operation in the class library is very simple. It is to add a common class and then paste the code in the previous ashx into this class almost exactly. But pay attention to the namespace and class name, because we will use it later.
Example 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 handler logic is not important. You can define it yourself. The key point is implementation: the members defined in IsReusable and ProcessRequest interfaces.
Next, we will register the handler in web. config of the website. If you use IIS7 or a later version and use the integration mode, you need to configure it as follows:
Add the following under the system. webServer \ handlers node:
<Add name = "ExampleHandler" verb = "*" path = "ex. axd" type = "EdiBlog. Core. Web. HttpHandlers. ExampleHandler, EdiBlog. Core"/>

Path is the path used to access handler, And the extension name must be registered in iis. If you are using a VM like me and cannot manage IIS on your own, do not use extended names that are not supported by IIS such as abc by default.
There are two parameters in type. The first is the complete name of the handler class, and the second is the Assembly name.
Now we can use ex. axd to access handler on the webpage!

Author: Wang Yujie

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.