Micah
Micah

Reputation: 116090

Retrieving cookies from HttpResponse

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.

Upvotes: 0

Views: 1284

Answers (3)

Micah
Micah

Reputation: 116090

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.

Upvotes: 1

Petar Kabashki
Petar Kabashki

Reputation: 6628

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

Upvotes: 0

mfeingold
mfeingold

Reputation: 7154

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

Upvotes: 0

Related Questions