AnOddProgrammer
asked on
HttpHandler gets 'Object reference not set to an instance of an object' when trying to access session vars.
Im programing a http handler in c# 2005 beta, and i need to access session vars, but when I tried to access them through the httpContext.Session i got the error 'Object reference not set to an instance of an object'. I already tried useing System.Web.SessionState.IR equiresSes sionState and System.Web.HttpContext.Cur rent.Sessi on, but neither of these worked. Does anyone know how to fix this?
ASKER
Here is the code to the HTTP handler
namespace FileHandler
{
//By directory file security
public class SecureFileHandler : System.Web.SessionState.IR equiresSes sionState, IHttpHandler
{
//Contructor
public SecureFileHandler()
{
}
//IHttpHandler Interface
//Process Request
public void ProcessRequest(System.Web. HttpContex t context)
{
//These lines cause an error
context.Response.Write(con text.Sessi on["GoodLo gin"].ToSt ring());
context.Response.Write(Sys tem.Web.Ht tpContext. Current.Se ssion["Goo dLogin"].T oString()) ;
//This line causes no error
context.Response.Write("Te st");
}
//IsReusable Var
public bool IsReusable
{
get
{
return true;
}
}
}
}
namespace FileHandler
{
//By directory file security
public class SecureFileHandler : System.Web.SessionState.IR
{
//Contructor
public SecureFileHandler()
{
}
//IHttpHandler Interface
//Process Request
public void ProcessRequest(System.Web.
{
//These lines cause an error
context.Response.Write(con
context.Response.Write(Sys
//This line causes no error
context.Response.Write("Te
}
//IsReusable Var
public bool IsReusable
{
get
{
return true;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thankyou for your help. The reson that it wasnt working was because the session vars had expired without me relizing it, now it works. Thanks again.
while this KB alert isn't necessarily your problem, it may give you something to go on, to investigate the aspnet worker process...
http://www.kbalertz.com/kb_841557.aspx