I have an ASHX file:
Object reference not set to an instance of an object.
On the line:
HttpContext.Current.Session["loggedIn"] = true
Is this how I use sessions properly?
I would guess that Session
is the culprit here; with reference here, you might want to try adding : IRequiresSessionState
to your handler (the code-behind for the ashx). So you should have something like:
public class Handler1 : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
context.Session["loggedIn"] = true;
}
public bool IsReusable
{
get
{
return false;
}
}
}
Note also that it is easier to talk to the context
passed in, but HttpContext.Current
should work too.
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