Accessing The Session Object From Within An HttpHandler (ASHX)
By default if you try to use the line above you’ll get an impressive null
var mySession = System.Web.HttpContext.Current.Session;
To make this work, the only thing you have to do is implement the
System.Web.SessionState.IReadOnlySessionState
on your handler.
using System.Web.SessionState;
public abstract class BaseHandler : IHttpHandler, IReadOnlySessionState {
public void ProcessRequest(HttpContext context)
{
var mySession = System.Web.HttpContext.Current.Session;
// your code here //
}
}
And that’s it!