views:

40

answers:

3

I have a controller action that I call via Ajax in which I set a cookie like this:

Response.Cookies["Notifications"].Value = "false";
Response.Cookies["Notifications"].Expires = DateTime.Now.AddYears(1);

In another controller action I am checking for this cookie like this:

if(Request.Cookies["Notifications"] != null && 
    Request.Cookies["Notifications"].Value =="false")
//Do something here

The problem is that Request.Cookies["Notifications"] is always null. I have verified that the cookie is getting set via FireBug. I'm testing this via visual studio's web built in web server.

Please help me understand what I'm doing wrong.

A: 

When in FireBug do you see the cookie sent back in the request? Also you can have a look at raw request to see if it is actually there

mfeingold
This is a good point. I checked and I don't see the cookies being sent back with the request. What would be causing this?
Micah
A: 

Just an idea/advice... You could fire Fiddler to sniff the actual http traffic and see how and if the cookies are being transferred in the http headers

Petar Kabashki
A: 

The problem was with the fact that I was also setting this:

Response.Cookies["Notifications"].Secure = true;

And of course the cookie isn't being sent because I'm not using Https.

Micah