Creating a custom HttpHandler is fairly simple, all you need to do is implement the IHttpHandler interface.
public class MyHttpHandler : IHttpHandler
I recently needed to access the Session object from within my HttpHandler to check if a value existed, however the HttpContext.Session object was always null! After several minutes of pulling my hair out I discovered I simply needed to implement an additional 'marker' Interface. As I only needed Read Only access to the session object I used IReadOnlySessionState as follows:
public class MyHttpHandler : IHttpHandler,
System.Web.SessionState.IReadOnlySessionState
However if you need write access simply use IRequiresSessionState:
public class MyHttpHandler : IHttpHandler,
System.Web.SessionState.IRequiresSessionState