471,337 Members | 1,054 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

session variables end up null

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?
Nov 19 '05 #1
4 1534
Check out:
http://weblogs.asp.net/bleroy/archiv...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" <ab*@rdk.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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?

Nov 19 '05 #2
thank you
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:up**************@tk2msftngp13.phx.gbl...
Check out:
http://weblogs.asp.net/bleroy/archiv...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" <ab*@rdk.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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?


Nov 19 '05 #3
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:up**************@tk2msftngp13.phx.gbl...
Check out:
http://weblogs.asp.net/bleroy/archiv...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" <ab*@rdk.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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?


Nov 19 '05 #4
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" <ab*@rdk.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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:up**************@tk2msftngp13.phx.gbl...
Check out:
http://weblogs.asp.net/bleroy/archiv...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" <ab*@rdk.com> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
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?



Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Roberto López | last post: by
9 posts views Thread by Greg Linwood | last post: by
1 post views Thread by Raed Sawalha | last post: by
13 posts views Thread by Alexander Widera | last post: by
1 post views Thread by Santosh | last post: by
22 posts views Thread by K. A. | last post: by
6 posts views Thread by =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.