Sharing session variables between pages

  • Thread starter Thread starter John Devlon
  • Start date Start date
J

John Devlon

Hi,

I've created 2 pages. On the first page i've created 2 session variables.
Going to the second page using the redirect function, the session variables
can't be located. Do i have to enable the session features in de web config
file or is there something else that went wrong?
Does anyone have an idea?

Page 1
Session("Login") = "John"
Session("Password") = "admin"
response.redirect("nextpage.aspx"")

Page 2
Dim strLogin as string = Session("Login")

Session("Login") is emty ....

Does anyone have an idea?

Thanx
john
 
Dim strLogin As String = Session("Login").ToString()

Mark's solution should work, but I would like to add something:

Dim strLogin as string = Session("Login")
The above code depends on an implicit conversion from object to
string. The session object is a collection of objects, not strings.
This means that you are not using Option Strict. I would highly
recommend you do so. It is a simple way to prevent bugs at compile
time instead of finding them at runtime.

- Norm
 
Back
Top