accessing cookies from different aspx/asp pages not working

goodluck11
goodluck11 used Ask the Experts™
on
c# creating cookie

 System.Web.HttpCookie UserNameCookie = new System.Web.HttpCookie("UserName");
                    UserNameCookie.Value = objUser.Username;
                    UserNameCookie.Expires = DateTime.Now.AddDays(5);
                    Response.Cookies.Add(UserNameCookie);

Classic ASP - reading cookie

Dim strUsername
strUsername = Request.Cookies("UserName")

response.write strUsername
response.end

it used to work, not anymore, how can we find the actual cookie value ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
the code below works, we see the UserName cookie on the browser, but cant retrieve values from asp neither can find its location

<%


dim intPollID
intPollID=19
Response.Cookies("PollId")=intPollID
Response.Cookies("PollId").Expires=Now+60

dim sval
sval= Request.Cookies("PollID")
response.write sval
response.end
Michel PlungjanIT Expert
Top Expert 2009

Commented:
Are the setting and getting both done on the same path and of not is the path set correctly?

http://msdn.microsoft.com/en-us/library/ms524757(v=vs.90).aspx


Path
Write-only. If specified, the Cookie is sent only to requests to this path. If this attribute is not set, the application path is used.



<%
  Response.Cookies("Type") = "Chocolate Chip"
  Response.Cookies("Type").Expires = "July 31, 2012"
  Response.Cookies("Type").Path = "/" ' cookie available to all folders
%>

Author

Commented:
we will try that. is path always required when writing cookies ?

will the ASP code be able to read the cookies and know where they are located after specifying the path / ?
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Michel PlungjanIT Expert
Top Expert 2009

Commented:
depends what MS means by If this attribute is not set, the application path is used.

So have a look if you changed path from the time it worked

Author

Commented:
We did tried, it works if on the same server, didn't work if on localhost or separate server

Dont know if the change took effect or not because this is on DNN, they tell us that only changing the .cs file and uploading only the .cs change should apply changes. Doesn't dotnet applications need the dlls re-compiled for all the code to take effect ?

It would work or not depending on the compilation/upload process...confused...
IT Expert
Top Expert 2009
Commented:
Not sure what you mean "same server or local host"
Cookies ONLY work on the same domain.
So aaa.yourserver.com can set cookies on bbb.yourserver.com but only if the domain attribute is set to yourserver.com
aaa.yourserver.com cannot set cookies on aaa.myserver.com

Author

Commented:
oh so we cannot set a cookie on www.domain1.com and read it on the server hosting www.domain2.com ?

Author

Commented:
arent the cookies on the client side ? browser reads them locally ?
Michel PlungjanIT Expert
Top Expert 2009

Commented:
Cookies can be set client and server side but whichever sets them has to be on the same domain as the page reading them

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial