What is the use of isreusable in handler?

Source: Internet
Author: User
What is the use of isreusable in handler?

What is the usage of the following code?
Public bool isreusable {
Get {
Returnfalse;
}
}

**************************************** *
Document 1:
**************************************** *
Ihttphandler. isreusable attribute
Gets a value indicating whether other requests can use an ihttphandler instance.
Attribute Value
True if the ihttphandler instance can be used again; otherwise, false.
Remarks
Explicitly set the isreusable attribute to true or false using the provided code to overwrite the isreusable property accesser (getter.

**************************************** *
Document 2:
**************************************** *
Isreusable in ihttphandler Interface
Network 2008-09-25
Ihttphandler isreusable Property
There isn't much clear info regarding this property on the net. it can bebetter in terms of performance when the property is set to true, but can causesome headaches if you have set it to true in the wrong scenario.

Public bool isreusable
{
Get
{
Return false;
}
}
The property is used to indicate if a single intantiation of your ihttphandlerimplementation can be used to process multiple concurrent requests. each clientrequest is considered to be a worker thread on the serverside when beingprocessed through the ASP. net pipeline. so, if we set isreusable = true, weneed to make sure that our processrequest method is threadsafe. theprocessrequest shocould not rely on any State that cocould be modified by otherconcurrent request threads. important when your ihttphandler implementation doesexpensive initialisations, otherwise it probabaly doesn't really matter if youreturn true or false (Since simple object allocation is fairly inexpensive in. net ). n. b. pages are never pooled.

Isreusable in ihttphandler Interface

The description of isreusable on msdn is not clear enough. If this attribute is set to true, the execution performance is better, but this may cause some headcache problems.
Public bool isreusable
{
Get {return false ;}
}
This attribute is used to indicate that if a single instance of your ihttphandler implementation class is used to process multiple requests. When processing through the ASP. NET pipeline, each client request is considered by the server as a worker thread. Therefore, if we set isreusable = true, we need to ensure that the processrequest method is thread-safe. Processrequest should not depend on any status values that may be modified by other requests. When your ihttphandler implementation class is busy with initialization, otherwise you do not need to consider whether isreusable returns true or false.
------------------------
Email: xiumang2006 at 126.com
Open-source directory:
Http://www.itjewy.com/
**************************************** *****************
Document 3:
**************************************** *****************
Thoughts on the reusability of httphandler (questions about isreusable attributes)

I have never understood the reusability of this ihttphandler. I have read an article and I feel a little bit confused. in general, each request is initiated by an httphandlerfactory to initialize a corresponding ihttphandler instance. Whether the handler is in the status does not depend on whether the class has a member variable. it depends on whether it depends on httpcontext. request, because the context is used as the parameter when it is initialized by the factory. It should be understood in this way. when isreusable is true, CLR will maintain an object pool. This is usually done only when the handler is created with a large overhead, and it should also be stateless.

But there is still a problem, that is, what if ihttphandler enables it to support output caching like aspx? Further research may be required.

The handler can be reused in such a case. This is obvious as long as it does not depend on context. Request. Of course, there cannot be any member variable.

In addition, it is best not to use it. the ashx file is directly stored on the web. config depends on the corresponding handler class, because these are more flexible for changing handler, and. write the Prize Code directly. in ashx, it will be compiled only when it is requested, slightly affecting the speed. the other is to consider the code security issues.

 

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.