IHttpHandler and Session

As a follow-up to yesterday's post, I needed the ImageRequestHandler to retrieve data from an external source, rather than always generating the same graph. For some reason, though, the Session object inside ProcessRequest's HttpContext was always null.

It turns out that you need to mark your class with IReadOnlySessionState or IRequiresSessionState if you want access to Session.

     class ImageRequestHandler : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            .
            .
            .

            // context.Session isn't NULL anymore!
        }
   }

Just leaving this information here in case I need it in future :)