session variables end up null

Discussion in 'ASP .Net' started by Abraham Luna, Sep 8, 2005.

  1. Abraham Luna

    Abraham Luna Guest

    i have a problem when i set a session variable on the login page. sometimes
    when i try to access it later it is null.

    this is how my login page works:

    Session["Typ"] = drEmployee["Typ"].ToString(); //set the typ session
    variable to employee typ. either: sales, admin, etc.
    FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    Request.QueryString["ReturnUrl"].ToString() : "secure/" + (Session["Typ"] ==
    "Admin" ? "admin/" : "") + "index.aspx");

    later on this code will fail:

    string strTyp = Session["Typ"].ToString();

    does anyone have any solutions. is there a setting or something i forgot to
    set?
     
    Abraham Luna, Sep 8, 2005
    #1
    1. Advertising

  2. Abraham Luna

    Karl Seguin Guest

    Check out:
    http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "Abraham Luna" <> wrote in message
    news:...
    >i have a problem when i set a session variable on the login page. sometimes
    >when i try to access it later it is null.
    >
    > this is how my login page works:
    >
    > Session["Typ"] = drEmployee["Typ"].ToString(); //set the typ session
    > variable to employee typ. either: sales, admin, etc.
    > FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    > Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    > Request.QueryString["ReturnUrl"].ToString() : "secure/" + (Session["Typ"]
    > == "Admin" ? "admin/" : "") + "index.aspx");
    >
    > later on this code will fail:
    >
    > string strTyp = Session["Typ"].ToString();
    >
    > does anyone have any solutions. is there a setting or something i forgot
    > to set?
    >
     
    Karl Seguin, Sep 8, 2005
    #2
    1. Advertising

  3. Abraham Luna

    Abraham Luna Guest

    thank you


    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > Check out:
    > http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Abraham Luna" <> wrote in message
    > news:...
    >>i have a problem when i set a session variable on the login page.
    >>sometimes when i try to access it later it is null.
    >>
    >> this is how my login page works:
    >>
    >> Session["Typ"] = drEmployee["Typ"].ToString(); //set the typ session
    >> variable to employee typ. either: sales, admin, etc.
    >> FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    >> Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    >> Request.QueryString["ReturnUrl"].ToString() : "secure/" + (Session["Typ"]
    >> == "Admin" ? "admin/" : "") + "index.aspx");
    >>
    >> later on this code will fail:
    >>
    >> string strTyp = Session["Typ"].ToString();
    >>
    >> does anyone have any solutions. is there a setting or something i forgot
    >> to set?
    >>

    >
    >
     
    Abraham Luna, Sep 8, 2005
    #3
  4. Abraham Luna

    Abraham Luna Guest

    ok, i changed my code to:

    FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    Session["Typ"] = drEmployee["Typ"].ToString();
    Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    Request.QueryString["ReturnUrl"].ToString() : "secure/" + (Session["Typ"] ==
    "Admin" ? "admin/" : "") + "index.aspx", false);

    according to the link, but i still get the null reference exception if i
    change the web.config file forcing the app to restart

    what can i do to fix this



    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > Check out:
    > http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Abraham Luna" <> wrote in message
    > news:...
    >>i have a problem when i set a session variable on the login page.
    >>sometimes when i try to access it later it is null.
    >>
    >> this is how my login page works:
    >>
    >> Session["Typ"] = drEmployee["Typ"].ToString(); //set the typ session
    >> variable to employee typ. either: sales, admin, etc.
    >> FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    >> Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    >> Request.QueryString["ReturnUrl"].ToString() : "secure/" + (Session["Typ"]
    >> == "Admin" ? "admin/" : "") + "index.aspx");
    >>
    >> later on this code will fail:
    >>
    >> string strTyp = Session["Typ"].ToString();
    >>
    >> does anyone have any solutions. is there a setting or something i forgot
    >> to set?
    >>

    >
    >
     
    Abraham Luna, Sep 8, 2005
    #4
  5. Abraham Luna

    Abraham Luna Guest

    ok i fixed it. when the app restarts it must reset the session variables. so
    on session start in global.asax i check to see if it is null and set it
    using the cookie info.

    "Abraham Luna" <> wrote in message
    news:%...
    > ok, i changed my code to:
    >
    > FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    > Session["Typ"] = drEmployee["Typ"].ToString();
    > Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    > Request.QueryString["ReturnUrl"].ToString() : "secure/" + (Session["Typ"]
    > == "Admin" ? "admin/" : "") + "index.aspx", false);
    >
    > according to the link, but i still get the null reference exception if i
    > change the web.config file forcing the app to restart
    >
    > what can i do to fix this
    >
    >
    >
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:...
    >> Check out:
    >> http://weblogs.asp.net/bleroy/archive/2004/08/03/207486.aspx
    >>
    >> Karl
    >>
    >> --
    >> MY ASP.Net tutorials
    >> http://www.openmymind.net/ - New and Improved (yes, the popup is
    >> annoying)
    >> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    >> come!)
    >> "Abraham Luna" <> wrote in message
    >> news:...
    >>>i have a problem when i set a session variable on the login page.
    >>>sometimes when i try to access it later it is null.
    >>>
    >>> this is how my login page works:
    >>>
    >>> Session["Typ"] = drEmployee["Typ"].ToString(); //set the typ session
    >>> variable to employee typ. either: sales, admin, etc.
    >>> FormsAuthentication.SetAuthCookie(tbEmpId.Text, false);
    >>> Response.Redirect(Request.QueryString["ReturnUrl"] != null ?
    >>> Request.QueryString["ReturnUrl"].ToString() : "secure/" +
    >>> (Session["Typ"] == "Admin" ? "admin/" : "") + "index.aspx");
    >>>
    >>> later on this code will fail:
    >>>
    >>> string strTyp = Session["Typ"].ToString();
    >>>
    >>> does anyone have any solutions. is there a setting or something i forgot
    >>> to set?
    >>>

    >>
    >>

    >
    >
     
    Abraham Luna, Sep 9, 2005
    #5
    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. Ram
    Replies:
    0
    Views:
    603
  2. John Smith
    Replies:
    2
    Views:
    2,252
    Sampsa Sohlman
    Jul 15, 2004
  3. Replies:
    5
    Views:
    27,530
    Mike Schilling
    Mar 29, 2006
  4. Dan Colgan

    HELP! - Session Start, Session End

    Dan Colgan, Sep 4, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    507
  5. javelin
    Replies:
    5
    Views:
    199
    Anthony Jones
    Dec 19, 2006
Loading...

Share This Page