How to Access SessionState in a custom HttpHandler
I create a lot of custom HttpHandlers to performa all sorts of tasks. I like them because you get complete control over the content produced by the server to satisfy the request. Occasionally I need to interact with the user's session. The other day I was working on a custm handler and needed to read a value in the session and I found I could not. I was just lost, then I remembered the HttpHander needed to implement the IRequiresSessionState interface.
public abstract class BaseHttpHandler : IHttpHandler, IRequireSessionState
Here is the interesting thing about the IRequiresSessionState interface, it is an empty interface. It has no members that actually need to be implemented. Somewhere under the innerworkings of the ASP.NET engine this triggers access to the Session state provider.