开发者

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

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?


This was happening because I was running the app under a different virtual directory. When I ran it on the original one, it worked.


I would suggest loading the IIS debug diagnostics tools. It is entirely possible that on that particular server there is a resource problem or unhandled exception that is killing that particular cookie AFTER it is added to the response but before it is flushed to the user. This is basically caused by a series of exceptions that occur in rapid succession causing rapid fail protection to shut down the w3wp.exe process that your page is running under. When the process is spooled back up to feed the response, the cookie is gone and all that goes out is the rendered html.

You might also try turning off rapid fail protection or altering memory settings/recycling settings on the application pool.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜