gpt4 book ai didi

c# - 设置过期的 HttpCookie 返回 DateTime.MinValue

转载 作者:太空狗 更新时间:2023-10-30 00:01:04 25 4
gpt4 key购买 nike

我在设置 cookie 时看到了一些奇怪的东西......

行动:

string cookieName = "foo";
string cookieValue = "bar";

//Set a cookie in the response, along with the Expires.
this.ControllerContext.HttpContext.Response.Cookies.Add(
new HttpCookie(cookieName, cookieValue)
{
Expires = DateTime.Now.AddHours(1)
}
);

调试时,我可以看到这个新的 cookie 有一个小时后的到期时间,但是,当我在 View 中查看 cookie 时,却没有到期...

查看:

<%= Request.Cookies.Get("foo").Value %>

返回 bar

<%= Request.Cookies.Get("foo").Expires %>

返回 01/01/0001 00:00:00

有什么想法吗?!

最佳答案

您正在查看请求 - 它不包含到期时间。服务器告诉客户端 cookie 何时过期;客户端也不需要告诉服务器:)

关于c# - 设置过期的 HttpCookie 返回 DateTime.MinValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1676901/

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