gpt4 book ai didi

asp.net - 当我向 HttpResponse 添加 cookie 时,如何删除 'no-cache="Set-Cookie"'?

转载 作者:行者123 更新时间:2023-12-02 18:40:30 24 4
gpt4 key购买 nike

我目前正在从网络服务返回一个 cookie,代码如下:

HttpResponse response = ...;
var cookie = new HttpCookie(cookieName)
{
Value = cookieValue,
Expires = expiresDate,
HttpOnly = true,
Path = "/",
Secure = true,
};
response.Cookies.Add(cookie);

这会导致在我的 Cache-Control header 中自动添加 no-cache 指令:

Cache-Control: public, no-cache="Set-Cookie", must-revalidate, max-age=60

我的客户碰巧通过直接不缓存响应来处理该指令。如果我在 no-cache 指令到达客户端之前手动删除它,缓存效果会很好。

如何防止 .NET 自动将此指令添加到包含 cookie 的响应中?

最佳答案

HttpResponse 根据 Cookies 集合是否为非空来确定是否应添加此指令。因此,如果您手动添加 header ,则可以在 .NET 中隐藏其存在:

response.AddHeader("Set-Cookie", String.Format(
"{0}={1}; expires={2}; path=/; secure; HttpOnly",
cookieName, cookieValue, expiresDate.ToString("R")));

关于asp.net - 当我向 HttpResponse 添加 cookie 时,如何删除 'no-cache="Set-Cookie"'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14005279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com