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