【发布时间】:2013-07-30 12:05:23
【问题描述】:
我正在尝试缓存 ActionResult。在特定的 ActionResult 中,我正在向 cookie 写入一些数据。输出缓存在该操作结果中不起作用。它适用于我不使用 Response.Cookies 的所有其他操作。请帮我解决这个问题。
我正在使用 ASP.NET MVC 4
编辑
(包括代码)
[OutputCache(Duration = 8000, VaryByParam = "*")]
public ActionResult List(SearchViewModel searchViewModel, int page = 1, int mode = 1)
{
HttpCookie ck = Request.Cookies["Geo"];
string lat = string.IsNullOrEmpty(Request.Params["lat"]) ? null : Request.Params["lat"];
string lng = string.IsNullOrEmpty(Request.Params["lng"]) ? null : Request.Params["lng"];
if (ck == null)
{
ck = new HttpCookie("Geo");
Response.Cookies.Add(ck);
}
if (lat != null)
{
ck["Lat"] = lat;
ck["Lon"] = lng;
ck.Expires = DateTime.Now.AddMonths(2);
Response.Cookies.Set(ck);
//this is the code which causes problem. If I remove this section catching will work
//other logic goes here..
}
}
【问题讨论】:
-
您能发布到目前为止您尝试过的内容吗?没有代码,我们无法看到您做错了什么并提供帮助。
-
我已经更新并包含了代码
-
我遇到了同样的问题,当在操作中写入 cookie 时 outputcache 将无法工作
标签: asp.net-mvc-3 caching asp.net-mvc-4 cookies outputcache