session variables end up null

A

Abraham Luna

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?
 
A

Abraham Luna

thank you


Karl Seguin said:
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 said:
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?
 
A

Abraham Luna

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 said:
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 said:
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?
 
A

Abraham Luna

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 said:
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 said:
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 said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top