Link to home
Start Free TrialLog in
Avatar of goodluck11
goodluck11

asked on

accessing cookies from different aspx/asp pages not working

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 ?
Avatar of goodluck11
goodluck11

ASKER

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
Avatar of Michel Plungjan
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
%>
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 / ?
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
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...
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh so we cannot set a cookie on www.domain1.com and read it on the server hosting www.domain2.com ?
arent the cookies on the client side ? browser reads them locally ?
Cookies can be set client and server side but whichever sets them has to be on the same domain as the page reading them