checking for an existing cookie


I have the following code:
   if (Response.Cookies["888"] == null)

                aCookie = new HttpCookie("888");
                aCookie.Value = System.Guid.NewGuid().ToString();                
                aCookie.Expires = DateTime.Now.AddDays(7);

I've just used a dummy name 888 for now but I'm trying to check to see if a cookie exists and if not create it.

However the code above always gets stepped over, even when the cookie shouldn't exist.

Am I doing the correct check?

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
Shouldn't you be checking Request.Cookies rather than Response.Cookies? Add to the Response; read from the Request.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.