Lossing my session variable

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
 
L

Lit

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
 
J

John Wright

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.
 
L

Lit

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top