【发布时间】:2017-10-16 01:25:21
【问题描述】:
我有一个 cookie,其中包含用于后端处理的 tmp 文件名。
try {
var cookie = new HttpCookie("TargetExcelFile") {
Name = "TargetExcelFile",
Path = "/",
Secure = true,
Expires = DateTime.Now.AddDays(1d),
Value = file
};
Response.Cookies.Add(cookie);
} catch (Exception e) {
throw new Exception("Create file cookie failed: " + e.Message);
}
在生产中它工作正常,但在 localhost 上,浏览器中的值是空白的。我可以设置断点并查看 cookie 在Response.Cookies.Add(cookie); 行的两种情况下都有一个值。
在localhost 上运行时,会创建 cookie,但在浏览器中没有任何值。
我认为Secure 标志可能是localhost 上的一个问题,所以我做了以下操作:
try {
var cookie = new HttpCookie("TargetExcelFile") {
Name = "TargetExcelFile",
Path = "/",
#if DEBUG
Secure = false,
#else
Secure = true,
#endif
Expires = DateTime.Now.AddDays(1d),
Value = file
};
Response.Cookies.Add(cookie);
} catch (Exception e) {
throw new Exception("Create file cookie failed: " + e.Message);
}
...它没有帮助。
想法?
【问题讨论】: