[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I read the same cookies in several pages ?

Posted on 2001-07-05
10
Medium Priority
?
297 Views
Last Modified: 2008-02-20
I have the following dirs and files :

/test1/index.asp
/test2/index.asp
/test1/read.asp
/test2/read.asp

I have this  Response.Cookies("Parent")("name") = "p1" in /test1/index.asp.
I have this  Response.Cookies("Parent")("name") = "p2" in /test2/index.asp.
I have this  Request.Cookies("Parent")("name") in both /test1/read.asp and /test2/read.asp.

When I ran the asp scripts, I discover /test1/read.asp only know how to read the cookies set by
/test1/index.asp. Why ?

How do I modify my scripts, so /test1/read.asp can read the cookies set by /test2/index.asp and
/test2/read.asp can read the cookies set by /test1/index.asp ?

0
Comment
Question by:idontknow12002
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 7

Expert Comment

by:John844
ID: 6255746
make sure that you refreshed your page.
0
 
LVL 7

Expert Comment

by:John844
ID: 6255750
the scenario that you described is exactly what I just did yesterday.  You are able to read the cookie set by the first page on the second page.  I did not see it originally, because my browser cached the page.
0
 
LVL 7

Expert Comment

by:John844
ID: 6255773
the only point that i see that might be causing you a bit of trouble would be the fact that if you set the cookie at the top of a page and try to read the contents of that cookie further down in the same page, you will see the original value, not the value that you are setting it to at the top of the page.


'value of cookie when page loads is "test"
Response.Cookies("Parent")("name") = "p1"

'this will write out "test"
response.write request.Cookies("Parent")("name")


the second time(and so on) the page is executed, it will write out "p1"
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:idontknow12002
ID: 6255779
I have refreshed so many time.
/test1/read.asp only read the cookies from /test1/index.asp.
0
 
LVL 4

Expert Comment

by:epeele
ID: 6255792
set the default path of the cookie to the root.

Response.Cookies("Parent").path = "/"
0
 
LVL 1

Expert Comment

by:user1234062501
ID: 6255945
I have your answer. Both read.asp scripts CAN read cookies written by both index.asp scripts. If it isn't working, you are doing something that you have not told us.

Are you writing session cookies or cookies with an expires value set?

Also, are you setting any other values for the cookies like domain or path?

If you send me your scripts I can diagnose your problem. I have just finished a project that uses cookies extensively and I have gained an extraordinary understanding of how cookies work.
0
 

Author Comment

by:idontknow12002
ID: 6255981
user1234,

I am very appreciate your help. Can you give me several hours to give you the script ?
0
 
LVL 1

Expert Comment

by:user1234062501
ID: 6255997
BTW, your server will only be able to read the last cookie you wrote using one of your index pages because you gave the cookie the same name. So if you run test1/index.asp you are writing "p1" and with test2/index.asp you are writing "p2" -- to the same cookie. (I don't know if that was obvious or not).
0
 
LVL 1

Expert Comment

by:user1234062501
ID: 6256005
Sure, take your time. I'll help you out. You can email it to me at trw@consultant.com
0
 
LVL 1

Accepted Solution

by:
user1234062501 earned 200 total points
ID: 6257059
Well, there is a minor problem with what you're doing. If you use session cookies you have to be sure to expire the content in your pages immediately. Otherwise the browser will fetch pages from the cache and your cookies won't have any effect.

Example: (This works the way you want)
================================
================================
[test1/index.asp]
<%
Response.Expires = -10000

If Len(Request.QueryString) <> 0 Then

     Response.Cookies("Parent")("name") = ""

Else

     If Len(Request.Cookies("Parent")("name")) = 0 Then
     
          Response.Cookies("Parent")("name") = "p1"
     
     ElseIf Request.Cookies("Parent")("name") <> "p1" Then
     
          Response.Redirect "../test2/index.asp"
     
     End If

End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
     <head>
          <title></title>
     </head>
     
     <body>
          <h1>You're on Test1 Index</h1>
          <a href="index.asp?d">delete cookie</a><br>
          test1/index.asp<br>
          <a href="../test2/index.asp">test2/index.asp</a><br>
          <%= "<br><b>Cookie = """ & Request.Cookies("Parent")("name") & """</b>" %>
     </body>
</html>
================================
================================
[test1/index.asp]
<%
Response.Expires = -10000

If Len(Request.QueryString) <> 0 Then

     Response.Cookies("Parent")("name") = ""

Else

     If Len(Request.Cookies("Parent")("name")) = 0 Then

          Response.Cookies("Parent")("name") = "p2"
     
     ElseIf Request.Cookies("Parent")("name") <> "p2" Then
     
          Response.Redirect "../test1/index.asp"
     
     End If

End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
     <head>
          <title></title>
     </head>
     
     <body>
          <h1>You're on Test2 Index</h1>
          <a href="index.asp?d">delete cookie</a><br>
          <a href="../test1/index.asp">test1/index.asp</a><br>
          test2/index.asp<br>
          <%= "<br><b>Cookie = """ & Request.Cookies("Parent")("name") & """</b>" %>
     </body>
</html>



If you want users to see the same page across multiple sessions you need to set the expiration for the cookie to whatever length of time you want them to continue seeing the same page.

If you take out the content expiration these pages allow you to type the URL in the browser and retrieve either page after deleting the session cookie.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question