By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 1,608 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

Getting error while setting session value

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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
"so*********@googlemail.com" wrote:
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
Jun 27 '08 #2

P: n/a
On Jun 12, 12:11 pm, Manish <Man...@discussions.microsoft.comwrote:
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

"sony.m.2...@googlemail.com" wrote:
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
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.