473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Lossing my session variable

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
Sep 7 '07 #1
4 1480
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
"John Wright" <ri***********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>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


Sep 7 '07 #2
Fixed it. It has to deal with the Response.Redirct. I needed to overload
it so it reads:

Response.Redirect(Request.QueryString("PageID"),fa lse)

This takes care of it.
"Lit" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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
"John Wright" <ri***********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>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



Sep 7 '07 #3
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"),fa lse)
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 Wright" <ri***********@hotmail.comwrote in message
news:Oa**************@TK2MSFTNGP05.phx.gbl...
Fixed it. It has to deal with the Response.Redirct. I needed to overload
it so it reads:

Response.Redirect(Request.QueryString("PageID"),fa lse)

This takes care of it.
"Lit" <sq**********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>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
"John Wright" <ri***********@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>>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




Sep 7 '07 #4
John Wright wrote:
Fixed it. It has to deal with the Response.Redirct. I needed to overload
it so it reads:

Response.Redirect(Request.QueryString("PageID"),fa lse)

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?

--
Göran Andersson
_____
http://www.guffa.com
Sep 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
1
by: Ann Leland | last post by:
I have been using session variables to pass a user name from one ASP page to another inside framesets for 9 months and it stopped working this week. I have made no code changes but there was a...
4
by: VB Programmer | last post by:
If I have a variable I want to share in my application what is the difference between just declaring a variable (Dim strMyVar as String) and using a session variable (Session("strMyVar"))? When...
5
by: Mark Rodrigues | last post by:
Hi Everyone, I have been fighting a problem for a while and I wonder if someone out there can help. This problem has been presented in a number of news postings previously but I am yet to see a...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
4
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
4
by: Don Miller | last post by:
I am using a Session variable to hold a class object between ASP.NET pages (in VB). In my constructor I check to see if the Session variable exists, and if it doesn't, I create one and populate it...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.