?
Solved

ASPSessionID cookie seems to kill JavaScript cookie

Posted on 2003-03-21
11
Medium Priority
?
678 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

719 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