我正在尝试将一些数据保存到 cookie 中,但是在回发之后,如果我在页面加载中检查 cookie 的值,该值始终为 null
这是我设置和获取 cookie 的方式
private static string GetCookie(string name)
{
return HttpContext.Current.Response != null ? HttpContext.Current.Response.Cookies[name].Value : string.Empty;
}
private static void SetCookie(string name, string value)
{
HttpContext.Current.Response.Cookies[name].Value = value;
HttpContext.Current.Response.Cookies[name].Expires = DateTime.Now.AddDays(ExpireTimeInDays);
}
最佳答案
GetCookie() 需要使用 Request.Cookie 而不是 Response.Cookie
关于c# - 为什么cookie在回发后总是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3470678/