I have never understood the reusability of ihttphandler. Today I read an article ArticleIn general, each request is initiated by an httphandlerfactory to initialize an ihttphandler instance. Whether the handler is in a State is not determined by 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 member variables.
In addition, it is better not to use the. ashx file, but to directly set the corresponding handler class in Web. config, because these are more flexible for changing handler and direct prizes.CodeIf it is written in. ashx, it will be compiled only when it is requested, slightly affecting the speed. In addition, it takes into account the code security issues.