3

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.. 
        }
     }
4

2 に答える 2

0

この他の質問で答えを見つけました。

リクエストからの出力をキャッシュしているように見えるOutputCacheため、同じパラメータを持つ同じリクエストの場合、アクション メソッドでコードを実行せず、同じ出力を返すだけです。したがって、後続のリクエストでコードが実行されることはありません。

他の投稿の回答には、いくつかの回避策があるようです。

于 2013-07-30T13:27:48.813 に答える