Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > session variables end up null

Reply
Thread Tools

session variables end up null

 
 
Abraham Luna
Guest
Posts: n/a
 
      09-08-2005
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?


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      09-08-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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?
>



 
Reply With Quote
 
 
 
 
Abraham Luna
Guest
Posts: n/a
 
      09-08-2005
thank you


"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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?
>>

>
>



 
Reply With Quote
 
Abraham Luna
Guest
Posts: n/a
 
      09-08-2005
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:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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?
>>

>
>



 
Reply With Quote
 
Abraham Luna
Guest
Posts: n/a
 
      09-09-2005
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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?
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP! - Session Start, Session End Dan Colgan ASP .Net 2 09-04-2007 03:12 PM
preventing session variables from going null javelin ASP General 5 12-19-2006 03:49 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
Tomcat JSP session beans not being removed at the end of the session John Smith Java 2 07-15-2004 12:46 PM
Session end event is firing immediately after session start Ram ASP .Net 0 05-19-2004 08:22 AM



Advertisments