Search code examples
c#asp.net-mvcasp.net-mvc-4cookieshttpcookie

Why are my site's cookies not working anymore?


Here is what my page cookies list looks like before doing anything:

enter image description here

I run through this code:

enter image description here

I get this result:

enter image description here

I can get it to say Account under Name, Value as CookieName1 and the value in userName along with the expire time only if I rename HttpCookie("Account") to say HttpCookie("Account1"), however, after doing so Account becomes Account1 and the process repeats itself until I rename that to Account2, etc.

Can anyone see any obvious issue with this?


Solution

  • The problem was because I was using if (Response.Cookies["Account"] != null) {} rather than if (Request.Cookies["Account"] != null) {}.