Generic handler aspx

Source: Internet
Author: User

public bool IsReusable
{
Get
{
return false;
}
}
property to change the value of this property to true, why doesn't it work? As explained by MSDN, this property means:

"Gets a value that indicates whether the IHttpHandler instance can be used by other requests, or true if the IHttpHandler instance can be used again;
False ”
See this explanation maybe some students will want to set the value of this property to true, you can reuse the IHttpHandler instance to achieve the purpose of improving performance.
But even if the value of this property is set to true. It's not going to work. Today, say this attribute,
We know that *.ashx is handed to simplehandlerfactory for processing, in which the call to the GetHandler () method directly returns the corresponding instance, which is the
The IsReusable attribute is not used in simplehandlerfactory.
First, from the context in the Maphandlerexecutionstep class. Handler = this._application. Maphttphandler (Context,
Request. RequestType, request. Filepathobject, request. Physicalpathinternal, false) start looking at the Maphttphandler method,
The function is to create a HttpHandler object, expand the method has the following code to note, httphandleraction mapping =
This. Gethandlermapping (context, RequestType, Path, useappconfig), the function of this method is to request from the Method (RequestType) and path (path) to get the corresponding configuration item, and the last return type is httphandleraction
。 If you expand the Gethandlermapping method, the general work is to find it from the cache first, and then look for the corresponding mapping from the configuration file if you can't find it.
Another place in the Maphttphandler method is IHttpHandlerFactory factory = this. GetFactory (mapping); the interface creates a
HttpHandler.
We know that ASHX can handle HTTP requests directly, both of which implement the IHttpHandler interface because the configuration is complete, and the default configuration information is as follows:


<add path= "*.ashx" verb= "*" type= "System.Web.UI.SimpleHandlerFactory" validate= "true"/>


And Simplehandlerfactory also implements the IHttpHandlerFactory interface, so you can create a IHttpHandler instance based on the requested path.

HttpApplication when processing a request, it does not directly create an instance of IHttpHandler, but rather gets a IHttpHandlerFactory object first.

Call the GetHandler () method again to get a IHttpHandler instance.

Generic handler aspx

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.