c# - IE9 中没有设置 Cookie

标签 c# asp.net cookies internet-explorer-9

我正在使用这段代码来设置 cookie。它在 Firefox 中完美运行。但在 IE9 中没有。

代码如下:

HttpCookie visitorCookie = new HttpCookie("VisitorCity", DdlCity.SelectedItem.Text)
{Expires = DateTime.Now.AddMonths(1)};
HttpContext.Current.Request.Cookies.Add(visitorCookie); // Add it to the header

最佳答案

通常当你想设置一个 cookie 时,你应该将它添加到响应中,而不是请求中:

HttpContext.Current.Response.Cookies.Add(visitorCookie);

是客户端浏览器,在发送后续的HTTP请求时,会附加cookie作为请求头。

关于c# - IE9 中没有设置 Cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8668162/

相关文章:

java - Android:BasicClientCookie/CookieStore 在 cookie 值周围添加引号

c# - 在 C# 中使用 Delphi 的结构数组和字符串

c# - 了解 C# 接口(interface)

asp.net - 如何用JQuery.UI Dialog和ASP.Net提交到服务器?

internet-explorer - InternetExplorer.Application 对象和 cookie 容器

javascript - javascript可以删除由http header 设置的cookie吗?

c# - Azure 移动服务、HttpClient、授权

c# - 使用 Entity Framework 6.1 CodeFirst 的 SQL Server 2014 内存优化表

asp.net - 当服务器的物理路径为 UNC 格式时,我的系统管理员是否疯狂 :-) Does ASP. NET MVC 中断?

c# - 在 ASP.NET 代码隐藏中禁用所有浏览器的缓存