?
Solved

ASPSessionID cookie seems to kill JavaScript cookie

Posted on 2003-03-21
11
Medium Priority
?
701 Views
Last Modified: 2012-08-13
In an ASP page called add_cookies.asp, I use JavaScript to write a cookie called ControlFlow. When I then look at JavaScript's document.cookie I see:

     SomeOtherCookie=xxxxxx; ASPSESSIONIDGGQQQNEU=KOMNHPBBGLJIIJBLFGFOCAKP; ControlFlow=Forward

My cookie is there, (at the end, after the ASP session ID). So everything's fine, so far.

Next, I use:

     Response.Redirect "see_cookies.asp"

to go to a different ASP page. That page uses JavaScript to look at document.cookie again. It sees:

     SomeOtherCookie=xxxxxx; ASPSESSIONIDGGQQQNEU=KOMNHPBBGLJIIJBLFGFOCAKP

Having moved to a different ASP page, I appear to have lost the JS cookie that was written by the first page.

If I turn the two pages into plain-old HTML/JavaScript pages and move "by hand" from add_cookies.html to see_cookies.html, my new
cookie survives just fine. (In that scenario there is, of course, no ASP Session ID cookie present.)

Two questions:

1) Am I analyzing the situation correctly? Is the ASP Session ID cookie really causing the Javascript cookie to disappear?

2) If so, what can I do to make my JS cookie survive the Redirect?

Thanks!

Charlie

P.S. I have to use JS cookies and ASP cookies together like this. The JS cookies get re-written when the visitor uses the Back
button, and that's important -- the JS cookie's job is to detect the use of the Back button.
0
Comment
Question by:cdarling
10 Comments
 

Author Comment

by:cdarling
ID: 8184106
Here's some further evidence to consider:

I created add_cookies_2.asp which writes the cookie using Response.Cookies("ControlFlow") = "Forward"

Doing it that way keeps the cookie "in front of" the ASPSessionID cookie, and it then survives the trip to see_cookie.asp, where it can be read by JavaScript.

That's a workaround that I can kinda use, but I'm not happy with it. So my offer of 500 points for a way to read and write cookies with JS across multiple ASP pages still stands.

And here's a tip: If you tackle this, close and re-open your browser between every test. Otherwise caching, etc will drive you nuts with bogus results.

Good luck, and thanks!!

Charlie
0
 
LVL 15

Accepted Solution

by:
gladxml earned 2000 total points
ID: 8185249
cdarling,

Try to check the expiration of your cookies
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8185269
cdarling,

try to check out the related links regarding setting of cookies expiration...

in asp

http://www.w3schools.com/asp/asp_cookies.asp

in javascript...

http://hotwired.lycos.com/webmonkey/98/29/index1a_page11.html

http://hotwired.lycos.com/webmonkey/98/29/index1a_page12.html?tw=programming


HTH...

HAppy programming....
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:avner
ID: 8194708
cdarling ,
do consider these two issues :

1. Cookie can be set to a certain path/file/server, make sure you set the path correctly.
2. There are session cookies and regular cookies, make sure you have not confused these two.
0
 
LVL 3

Expert Comment

by:Adelphi
ID: 8215727
Are you buffering the asp page?  If buffer=true, then the asp results are being held in buffer and not sent to the client until the whole page is processed.  Since you do a response.redirect before that happens, the cookie doesn't really get written.

Try buffer=false or else do a buffer flush after the cookie code but before the redirect.

Note that any buffer commands should be the first line of the page.
0
 
LVL 3

Expert Comment

by:Adelphi
ID: 8215752
Sorry, I should have explained a bit further...

Buffering is TRUE by default.

So try putting :

<%Response.Buffer=false%>

as the first line of your page.
0
 
LVL 3

Expert Comment

by:jtolar
ID: 8799082
I agree with Adelphi, A redirect will close all processing from that point and redirect. If buffering is on then your cookie is not being sent to the client.
Response.buffer = false should be your first line in the asp code. Starting with ASP 3.0 (win 2000/IIS5) Buffering is true by default.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9115271
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
 
LVL 15

Expert Comment

by:gladxml
ID: 9163841
cdarling,

Does the link that I had provided does not help in resolving the problem...

Regards,
gladxml
0
 
LVL 6

Expert Comment

by:Programming_Gal
ID: 9712444
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept gladxml's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Programming_Gal
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

588 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