Cookies NULL On Some ASP.NET Pages (even though it IS there!)

Posted by DaveDev on Stack Overflow See other posts from Stack Overflow or by DaveDev
Published on 2010-01-20T14:51:39Z Indexed on 2010/03/13 18:35 UTC
Read the original article Hit count: 121

Filed under:
|

Hi folks

I'm working on an ASP.NET application and I'm having difficulty in understanding why a cookie appears to be null.

On one page (results.aspx) I create a cookie, adding entries every time the user clicks a checkbox. When the user clicks a button, they're taken to another page (graph.aspx) where the contents of that cookie is read.

The problem is that the cookie doesn't seem to exist on graph.aspx. The following code returns null:

Request.Cookies["MyCookie"];

The weird thing is this is only an issue on our staging server. This app is deployed to a production server and it's fine. It also works perfectly locally.

I've put debug code on both pages:

StringBuilder sb = new StringBuilder();
foreach (string cookie in Request.Cookies.AllKeys)
{
    sb.Append(cookie.ToString() + "<br />");
}

this.divDebugOutput.InnerHtml = sb.ToString();

On results.aspx (where there are no problems), I can see the cookies are:

MyCookie __utma __utmb __utmz _csoot _csuid ASP.NET_SessionId __utmc

On graph.aspx, you can see there is no 'MyCookie'

__utma __utmb __utmz _csoot _csuid ASP.NET_SessionId __utmc

With that said, if I take a look with my FireCookie, I can see that the same cookie does in fact exist on BOTH pages! WTF?!?!?!?! (ok, rant over :-) )

Has anyone seen something like this before? Why would ASP.NET claim that a cookie is null on one page, and not null on another?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about cookies