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