0

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.

3
  • 1
    Does your server always start on the same port? Commented Feb 3, 2010 at 0:40
  • And does the domain of the second page match the domain of the cookie? Commented Feb 3, 2010 at 1:43
  • The domain is showing up as "localhost" and yes it's on the same domain, but no the server doesn't always start on the same port. However each request is on the same port when they are made. Commented Feb 3, 2010 at 1:55

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

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?
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.