Quantcast
Channel: How do Cookies Work in ASP.NET? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How do Cookies Work in ASP.NET?

$
0
0

The website where I work is made up of several projects (written in several languages). Right now we have to use some awkward code in query strings and session variables to keep a person logged in when they go from project to project. Since cookies are domain specific we're trying to convert to them since they can be set in one project using one language yet be accessed by a different project (on the same domain) using a different language.

However I am having problems changing the value of a cookie and deleting them. Or to be more specific, I'm having trouble having any changes I make to a cookie stick.

For example in my logout code:

if (Request.Cookies["thisuserlogin"] != null){    HttpCookie myCookie = new HttpCookie("thisuserlogin");    myCookie.Value = String.Empty;    myCookie.Expires = DateTime.Now.AddDays(-1d);    Response.Cookies.Add(myCookie);    Response.Cookies.Set(myCookie);    litTest.Text = myCookie.Expires.ToString() +"<br />"+ Request.Cookies["thisuserlogin"].Expires.ToString();}

I wind up with one line being yesterday and the next line being 1/1/0001 12:00:00 even though they SHOULD be the same cookie. So why is it that even though the cookie was set, it's value did not change? Is there a way to force the user's computer to update a cookie's value, including deletion?

Thank you very much.PS Any URLs you can provide to give an easy-to-understand primer for cookies would be appreciated.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images