开发者

Why is Cookie available in Request immediately after setting using Response?

In pageload, if you do Response.Cookies.Add(..开发者_如何学运维., immediately in the next line, you can access that cookie via Request.Cookies(...

I know that under the covers, the cookie is added to Request.Cookies by .net, but the original request never had that cookie.

If what I'm saying is correct, why is it this way? Shouldn't the cookie be available in the following request? Shouldn't the immediate access to Request.Cookies(... be null?


You're right, ASP.NET does do that behind the scenes:

After you add a cookie by using the HttpResponse.Cookies collection, the cookie is immediately available in the HttpRequest.Cookies collection, even if the response has not been sent to the client.

-- HttpRequest.Cookies page on MSDN

Why is it like that? At a guess, it's because that's how developers expect it to work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜