Getting error while setting session value

Discussion in 'ASP .Net' started by sony.m.2007@googlemail.com, Jun 12, 2008.

  1. Guest

    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 12, 2008
    #1
    1. Advertising

  2. Manish Guest

    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
    "" 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
    >
     
    Manish, Jun 12, 2008
    #2
    1. Advertising

  3. Guest

    On Jun 12, 12:11 pm, Manish <> wrote:
    > 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
    >
    > "" 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 12, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ^CrazyCoder^
    Replies:
    3
    Views:
    7,328
    Terrence Benade
    Sep 15, 2003
  2. David
    Replies:
    1
    Views:
    523
    David
    Jul 19, 2004
  3. King_Kong
    Replies:
    2
    Views:
    131
    Gunnar Hjalmarsson
    May 23, 2005
  4. Madni
    Replies:
    0
    Views:
    81
    Madni
    Apr 5, 2006
  5. George
    Replies:
    4
    Views:
    679
    Roedy Green
    Jun 28, 2012
Loading...

Share This Page