在服务器端,当我收到 http 请求时,我添加一个新的 cookie,如下所示:
HttpContext.Response.Cookies.Add(it);
如果我立即在 HttpContext.Request.Cookies 中查询我刚刚添加的 cookie 的名称,我会得到它,尽管我认为我不应该,因为我什至还没有完成我的请求处理,没有发送尚未回复客户。
请求和响应的 cookie 集合是否应该彼此不同?就像 http 请求/响应 cookie header 一样。
谢谢
最佳答案
这是预期的且有据可查的行为。请参阅HttpResponse.Cookies :
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.
关于c# - Response.cookies出现在request.cookies中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19557365/