Last post Dec 18, 2011 05:32 AM by ahmedilyas
Dec 17, 2011 11:02 AM|ahmedilyas|LINK
no matter what I do, I am unable to read the cookie I have set!
HttpCookie myCookie = new HttpCookie("TheProject");
myCookie.Domain = Request.Url.Host;
myCookie.Expires = DateTime.Now.AddYears(1);
myCookie["Username"] = this.txtUsername.Text
HttpCookie cookieRead = Request.Cookies["TheProject"];
if (cookieRead != null)
this.txtUsername.Text = cookieRead["Username"];
Now, on the postback, I can see the cookie being set. AND I can read it (in debug mode on the same place). but when I re-read the cookie from another page - cookie is not found or if it is found, the values are not being persisted.
Dec 17, 2011 11:19 AM|Nazm|LINK
Salam Alikom Ahmed
Try to use Response as alternative to Request.
Dec 17, 2011 11:23 AM|ahmedilyas|LINK
It does not make any difference if you use Response. Using response is bad when READING a cookie as if the cookie does not exist, it will create the cookie and overwrite the cookie (if some reason it existed)
The problem is, once you set the cookie.... you cannot read it from any other page. or if you do manage to obtain the cookie - the content/value is empty completely
Dec 17, 2011 11:49 AM|Nazm|LINK
Have you tried to set it as follow:
Response.Cookies["Username"].Value = "XY";
Dec 17, 2011 11:51 AM|ahmedilyas|LINK
yes. still the same result :(
Dec 17, 2011 12:04 PM|Nazm|LINK
Does Username a property of TheProject!
Try This :
Dec 17, 2011 12:09 PM|ahmedilyas|LINK
ill try that. but even if I do it without the multiple values... I would still expect .Value to have the value, like when it has been set.
theCookie.Value = this.txtUsername.Text;
that works when setting and getting on the same page request. but on the next postback or even on a different page...the cookie is not found or value is not set
Dec 17, 2011 12:23 PM|Nazm|LINK
Are you using different subdomains?
if so refer to this thread
Dec 17, 2011 12:28 PM|ahmedilyas|LINK
nope. no subdomains at all. nothing different. SAME domain. SAME host.
Dec 17, 2011 01:29 PM|Nazm|LINK
Make sure you didn't change the value of an element after setting it the 1st time.
losing cookie value
Otherwise post the 3 pages(code) to understand the case well...
Dec 17, 2011 03:16 PM|ahmedilyas|LINK
that IS the entire code...
Dec 18, 2011 02:05 AM|Pradeep Kr. Sharma|LINK
problem is in your browser settings which is not able to create cookies, so change your browser settings as default.
Check your code with firefox. it will work fine.
If you are checking with IE then comment below section in your code.
//myCookie.Domain = Request.Url.Host;
Dec 18, 2011 05:32 AM|ahmedilyas|LINK
I mentioned earlier - my browser settings are fine. even setting it to the very lowest setting does not work.
commenting out the .Domain property still does not work.