Save JavaScript Cookies in ASP Cookies

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/69222?pagenum=1
05 November 2025, 12:35

Topic


mafifi
Save JavaScript Cookies in ASP Cookies
11 March 2010, 13:27


I have a web page that pulls information from different applications on diffrent servers. One such application sends JavsScript cookies data to the client. Is it possible to grab these values and stuff them in ASP Session Variables or Cookies? I would love to see a working sample.

 

Replies ...


HuwR
11 March 2010, 14:25


not sure what you are after, a cookie is a cookie it is a text file saved on the users machine they are language agnostic so you can just read them using ASP the same as you can read them using javascript
mafifi
11 March 2010, 16:07


Originally posted by HuwR
not sure what you are after, a cookie is a cookie it is a text file saved on the users machine they are language agnostic so you can just read them using ASP the same as you can read them using javascript

This is what I am trying to do:
Code:


<script language="javascript" type="text/javascript">
document.cookie = "mycookie=2; expires=1/1/2020; path=/;";
</script>


<%
Dim myBrownie
'get the cookie
myBrownie = Request.Cookies("mycookie")
Response.Write("You ate " & myBrownie & " brownies")
%>

I do not see the value of the cookie until after I refresh the page.
HuwR
11 March 2010, 18:02


well you won't because the asp code gets executed on the server before the page is sent to the client and then the javascript runs. so there is no cookie at the time request.Cookies is called
mafifi
11 March 2010, 19:23


This is the problem which I am trying to resolve. I am thinking about using Ajax to refresh the page and pull the cookie value(s).
HuwR
12 March 2010, 04:27


maybe if you explain what you are trying to achieve we can offer suggestions, writing a cookie from the client and then trying to read it from the server without a postback just won't work, so what exactly are you trying to accomplish ?
mafifi
12 March 2010, 07:09


Here's what I would like to happen:

Application 'A' (Non ASP) will authenticate the user and send the 'User Information' to application 'B' (ASP) as JavaScript cookies. I want to delete the JavaScript cookies as soon as I am able to hold their values in ASP session variables and some of the 'User Information' will be encrypted and saved in a persistent ASP cookie to be used as needed throughout the application.
Shaggy
12 March 2010, 10:19


As Huw said, cookies operate independent of language so you could set the cookie in application A before transferring to application B which would then be able to read the cookie.
HuwR
12 March 2010, 11:12


I'm still not following what you are trying to do,
You can't send information form A to B as javascript cookies, cookies are NOT javascript cookies are text files stored on the clients machine.
What is application A ? if it is able to write a cookie, then application B can just read them using ASP (by the way ASP is not a language either so can be vbscript or javascript), what are you trying to do exactly, pleasse explain more.
© 2000-2021 Snitz™ Communications