I am using:
if (string.IsNullOrEmpty(myHttpContext.Request.QueryString["code"]))
{
if (myHttpContext.Session == null || myHttpContext.Session["code"] == null)
{
OutputError("Code", "Invalid code.");
}
else
{
code = myHttpContext.Session["code"].ToString();
}
}
else
{
code = myHttpContext.Request.QueryString["code"];
myHttpContext.Session.Add("code", code);
}
However I keep getting the error: Object reference not set to an instance of an object.
For: myHttpContext.Session.Add("code", code);
All I want to do is set a simple session, someone please help this is driving me crazy.
Has your IHttpHandler (ashx) class implemented IRequireSessionState? Otherwise the Session object will not be accessible.
public class MyHandler : IHttpHandler, IRequireSessionState
{
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext ctx)
{
// your code here
}
}