Getting error while setting session value

  • Thread starter Thread starter sony.m.2007
  • Start date Start date
S

sony.m.2007

Hi,
When i try to set a value for a session variable I'm getting a object
refence not set error

I tried two methods as below
HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;

For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
Kindly help me out.

Thanks,
Sony
 
Hi Sony,

I tried the code and it works fine.

protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
Response.Write(Session["AppStartTime"].ToString());
}

Regards,
Manish
www.componentone.com
 
Hi Sony,

I tried the code and it works fine.

protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
Response.Write(Session["AppStartTime"].ToString());
}

Regards,
Manishwww.componentone.com

Hi,
When i try to set a value for a session variable I'm getting a object
refence not set error
I tried two methods as below
HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
Kindly help me out.
Thanks,
Sony
Hi,
My class implements IHttpModule
and I'm assigning the session value at onbeginrequest method

public class TestHTTPModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest +=
(new EventHandler(this.Application_BeginRequest));
}
private void Application_BeginRequest(Object source,
EventArgs e)
{
HttpContext.Current.Session.Add("AppStartTime",
DateTime.Now);
HttpContext.Current.Session["AppStartTime"] = DateTime.Now;
}
}

If u try like above you will get the error message.
How to solve this?

Thanks,
Sony
 
Back
Top