Question

Hello I see on msnd that anything that inherits from the Ihttphandler interface has access to a httpcontext object (under the remarks section of the page in below link)

msdn HTTPContext

My question is how does the interface expose this object...I don't see any property of type httpcontext in the interface. I do see the "ProcessRequest" method that is taking in an httpcontext object. But i'm not seeing how that is resulting in the httpcontext object being exsposed directly from the interface as the msnd page says.

Forgive me if i'm missing a key concept here, fairly new to this. Thanks

Was it helpful?

Solution

No, it is passed into the ProcessContext method only. The handler then interacts with that HttpContext instance as it's the context for the request. You can pass around the context instance to various other methods and such as much as you would like.

Why it is done this way becomes more clear if you look at the documentation about the IsReusable property. When that property is true, multiple requests can be served by the same handler instance, and thus they must be supplied a separate HttpContext to work.

Now, if you specify IsReusable as false, you can then store the HttpContext instance from ProcessRequest in a property on the instance. Not sharing the handler can cause performance issues under some scenarios, but you likely won't need to worry about that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top