Get the App
SLTechnology News&Howtos  ›  Development  › 

How does ASP.NET write ashx to the class library and call it on the page?

Shulou Source: shulou.com Published: 2022-06-03 06:17:54 10月13日 Update

This article will explain in detail how ASP.NET ashx written in the class library and call on the page, Xiaobian feel quite practical, so share to everyone to make a reference, I hope you can have some harvest after reading this article.

The operation of building Http Handler in class library is very simple, just add a normal class, and then paste the code in ashx almost exactly into this class. But pay attention to namespaces and class names, because we'll use them later.

Sample Handler:

The code is 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 to implement the members defined in the IsReusable and ProcessRequest interfaces.

Next we're going to register this handler in the web.config of the site. If you are using IIS7 and above and are using integration mode, configure it like this:

Under the system.webServer\handlers node, add:

Path is the path to access the handler, and the extension needs to be registered in iis. If you are using a virtual host like me and cannot manage IIS yourself, please do not use extensions that IIS does not support by default, such as abc.

Type takes two parameters, the first is the full name of the handler class, and the second is the name of the assembly.

Now we can access handler on the web page using ex.axd!

About "ASP.NET how to write ashx class library and call on the page" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Articles pages libraries two code more logic good practical ordinary important exactly the same can not be themselves host key key points content parameters names that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Microsoft vpn Shulou Tech Info