Lossing my session variable

  • Thread starter Thread starter John Wright
  • Start date Start date
J

John Wright

I use the following code to set a session variable for people I have
authenticated to my site:

For Each row As DataRow In foundRow

Session("Login") = row.Item(1).ToString

Exit For

Next

Response.Redirect(Request.QueryString("PageID"))



The Session("Login") get set just fine, but when I do the redirect the page
that loads checks for the following:



If Session("Login") = "" OrElse IsNothing(Session("Login")) Then

Response.Redirect("Login.aspx?PageID=" & Request.Path)

Else

Label1.Text &= " " & Session("Login").ToString

End If



When I check the session variable here, it is empty. Does anyone know why?



John
 
where are you putting the code Session("Login") = row.Item(1).ToString
why a for loop for executing only once?
are you within the same domain?
are you within asp.net always?

Lit
 
Fixed it. It has to deal with the Response.Redirct. I needed to overload
it so it reads:

Response.Redirect(Request.QueryString("PageID"),false)

This takes care of it.
 
John,

This does not make any sense to me. I tried your code and it works fine on
my end. the session has the correct info picked from the second page.

Response.Redirect(Request.QueryString("PageID"),false)
the Boolean parameter, indicates whether execution of the current page
should terminate.

I hope you are right and explain why it works that way or someone else can
explain this.

Thank you,

Lit
 
John said:
Fixed it. It has to deal with the Response.Redirct. I needed to overload
it so it reads:

Response.Redirect(Request.QueryString("PageID"),false)

This takes care of it.

No, it doesn't. The only difference is that the execution of the code
doesn't end there, but continues to run the rest of the code. As that
doesn't change how session variables work, there has to be something in
the code below that makes a difference.

Do you set the session variable elsewhere in the code?

The Redirect method normally uses an exception to end the execution. Do
you have any error handling that catches exceptions that it shouldn't?
 
Back
Top