Getting error while setting session value

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
 
M

Manish

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
 
S

sony.m.2007

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top