473,246 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 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 1611
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Al Jones | last post by:
This is a repost form the vbscript newgroup - if this isn't the appropriate group would you point me toward one that is. Basically, I seem to be losing session data part way though preparing an...
10
by: Roberto López | last post by:
Hi, I´m doing an asp.net application that uploads and downloads files and folders between the client and the server on my intranet. To do this I have create threads and it runs Ok but I need to...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
1
by: Steve Remer | last post by:
My application (relevant code snippets below) originally used Session variables in order to maintain state from page to page. After being unable to solve the mystery of why those variables were...
1
by: Raed Sawalha | last post by:
Hello: My problem is that in my login page, I authenticate the user and set a session variable: Session("strname") = dr("userlname") & ", " & dr("userfname") & " " & dr("usermi")...
13
by: Alexander Widera | last post by:
hi, who has seen the follow problem or could help please? i visit a page .... i read a sesssion-var . ... everythink works...... i visit the page again..... error ... the sessionvar is null .... i...
1
by: Santosh | last post by:
Dear All i am writting a code sending mail with attachement. i am writting code for sending mail in one page and code for attaching a file in the next page. aftet attaching a file i am taking...
22
by: K. A. | last post by:
I have two servers at work, 'A' for testing and development, and server 'B' for production. On server A, I wrote a PHP test code to login users then direct them to a personalized page. This is...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
6
by: ChrisAtWokingham | last post by:
I have been struggling with unexpected error messages on an ASP.NET system, using SQL and C#. The application draws organisation charts, based on data stored in the SQL database. Some of the chart...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.