Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Setting Session Varaibles from a Function


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sun, 16 Feb 2003 03:47:50
Hello Everyone and thanks for your help in advance.  I am working on a 
forms validation application that checks the user name and password 
aagainst a SQL Server database.  This checking is done in a function that 
returns either "true" or "false" depending on if there is a match.  Where 
I am running into problems is that, within this same function, I am 
trying to set a session variable for the users first and last names in 
order to personalize some of the screens.  The code I am using is:

'Code to perform database lookup into a datareader

If myReader.Read() Then
      Return True

      HttpContext.Current.Session("AccessLevel") = myReader
("szUserRights")
      HttpContext.Current.Session("FirstName") = myReader("szFirstName")
      HttpContext.Current.Session("LastName") = myReader("szLastName")

Else
      Return False
End If

However, the session variables never appear to get set, since, when I 
access them from another page, they return nothing.  But when I move the 
above code into the Page_Load sub, the session variables are set 
correctly.  I am not sure why this isn't working.  Any help would be 
greatly appreciated.  Thanks.
Message #2 by "Shreekar" <joshishreekar@r...> on 18 Feb 2003 09:46:19 -0000
Hi High,
  Maybe you got it already figured out, but since I saw no reply 
posted to ur query, here it goes.

<<
If myReader.Read() Then
      Return True ---> THE FUNCTION EXITS (no further code is 
executed)

      HttpContext.Current.Session("AccessLevel") = myReader
("szUserRights")
      HttpContext.Current.Session("FirstName") = 
myReader("szFirstName")
      HttpContext.Current.Session("LastName") = 
myReader("szLastName")

>>
Regards
Shreekar Joshi

Subject: Setting Session Varaibles from a Function
 From: "Hugh McLaughlin" <hugh@k...>
Date: Sun, 16 Feb 2003 03:47:50
X-Message-Number: 3

Hello Everyone and thanks for your help in advance.  I am working 
on a
forms validation application that checks the user name and 
password
aagainst a SQL Server database.  This checking is done in a 
function that
returns either "true" or "false" depending on if there is a match.  
Where
I am running into problems is that, within this same function, I 
am
trying to set a session variable for the users first and last 
names in
order to personalize some of the screens.  The code I am using 
is:

'Code to perform database lookup into a datareader

If myReader.Read() Then
      Return True

      HttpContext.Current.Session("AccessLevel") = myReader
("szUserRights")
      HttpContext.Current.Session("FirstName") = 
myReader("szFirstName")
      HttpContext.Current.Session("LastName") = 
myReader("szLastName")

Else
      Return False
End If

However, the session variables never appear to get set, since, 
when I
access them from another page, they return nothing.  But when I 
move the
above code into the Page_Load sub, the session variables are set
correctly.  I am not sure why this isn't working.  Any help would 
be
greatly appreciated.  Thanks.
----------------------------------------------------------------------


Regards
Shreekar Joshi

  Return to Index