We help IT Professionals succeed at work.

Cookies Problem

bbala
bbala asked
on
Hi,
 When I do set a cooke like
 
<%response.cookies("username")="bala"%>

in page1.asp

and try to get it in page2.asp with

 <%response.write(request.cookies("username"))%>

I am getting the username.

But if I copy the page2.asp URL and minimize the page2.asp
and trying the URL in new IE / NN ,it  is not printing my (cookie)username

what I have to do to get that. please explain.

regards,
bala
Comment
Watch Question

Michel SakrRounded IT Consultant / Projects manager / Cloud Consultant / IT Planning
CERTIFIED EXPERT

Commented:
you might need to set an expiry for your cookie..

<%
response.cookies("Username") = "bala"
response.cookies("Username").Expires = Now() + 1 'expires tomorrow%>

<%= request.cookies("Username")%>

Author

Commented:
No.. It is not working.
If I run Page1.asp once and if i immediately run page2.asp
(which has <%= request.cookies("Username")%> )
then I am closing the browser.
I am opening the New browswer window, If I type the url of page2.asp , It is not printing the cookie value..

Pl. Give a good result.

bala

Commented:
Try something like this
Response.Cookies("Username") = "bala"
Response.Cookies("Username").Expires = #July 4, 2002#

You can also try change your security options for your webbrowser. (in IE, Tools->Intenet Options... -> security tab -> Custom Level -> Cookies -> Allow cookies that are stored on your computer)

Commented:
Setting the Expires property of the cookie is not enough. Add the following code before setting the value for the cookie:

Response.Cookies.Path = "/"

OR

Response.Cookies.Domain = "yourdomain"

Set the Domain if you want the cookie requests to be visible in the domain. Set the Path if you want cookie requests to be visible in the path only. Play around with these properties... Enjoy!
Try this....

p1.asp:
=======
<%@ Language=VBScript %>
<%
Response.Cookies("test")="Testing"
Response.Expires=0
%>
<a href="p2.asp">click</a>

p2.asp:
=======
<%@ Language=VBScript %>
<%=Request.Cookies("test")%>


Good Luck...:)

Commented:
Are you typing the URL in exactly the same? Some versions of IE are case sensitive (for the domain at any rate)...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.