I have the following simple handler (removed some code for vissibilty sakes, but the below still fails)
<%@ WebHandler Language="C#" Class="DownloadHandler" %>
using System;
using System.Web;
public class DownloadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Session["t1"] != "true")
{
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
The line if (context.Session["t1"] != "true")
is failing with "Object reference not set to an instance of an object." and i dont quite get why that is?
That's because for http handler in order to access Session
you need to explicitly implement IRequiresSessionState
interface.
Keep in mind that if you do that there will be an implicit locking on the session object and you won't be able to have multiple handlers in the same session state processed simultaneously.
There is an IReadOnlySessionState
interface as well for read-only session state access.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With