本文介绍了加入后的查询字符串打破RemoveOutputCacheItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC 3,我outputcaching一个JsonResult是这样的:

In MVC 3 I was outputcaching a JsonResult like this:

[OutputCache(Location = OutputCacheLocation.Server, Duration = 21600, VaryByParam = "None", VaryByCustom = "tenant")]
    public JsonResult NotifyTasks(int id) {
         return Json(new {pending = 5}, JsonRequestBehavior.AllowGet);
        }
    }

要获得JSON的网址是:

The URL to get the JSON was:

http://localhost/foo/notifytasks/1

有时我的无效页面缓存用一个简单的

At times I invalidate the cache pages with a simple

HttpResponse.RemoveOutputCacheItem("foo/notifytasks");

方法签名已经改变,RemoveOutputCacheItem不再起作用。该URL现在有查询字符串?状态=状态1 附加,这打破了RemoveOutputCacheItem。

The method signature has changed and RemoveOutputCacheItem no longer works. The URL now has the querystring ?status=Status1 appended and this broke RemoveOutputCacheItem.

[OutputCache(Location = OutputCacheLocation.Server, Duration = 21600, VaryByParam = "None", VaryByCustom = "tenant")]
    public JsonResult NotifyTasks(int id, string status) {
         return Json(new {pending = 5}, JsonRequestBehavior.AllowGet);
        }
http://localhost/foo/notifytasks/1?status=Status1

我如何获得RemoveOutputCacheItem与追加的查询字符串工作?

How do I get RemoveOutputCacheItem to work with an appended querystring?

推荐答案

我有同样的问题,我认为它归结到的只接受的路径和查询字符串不是路径的一部分(路径<?> URL)。
如果你想注册一个独立的路线

routes.MapRoute(
   DifferentRoute
   {控制器} / {行动} / {ID} / {}状态,
   新{控制器=信息,行动=索引,ID = UrlParameter.Optional,状态= UrlParameter.Optional}
            );

I had the same problem, I think it comes down to that RemoveOutputCacheItem only accepts a path and a querystring is not part of the path (path <> url ?).If you would register a seperate route
routes.MapRoute( "DifferentRoute", "{controller}/{action}/{id}/{status}", new { controller = "Information", action = "Index", id = UrlParameter.Optional, status = UrlParameter.Optional } );

的Htt presponse.RemoveOutputCacheItem(富/ notifytasks / 1 /状态1);
正常工作

then
HttpResponse.RemoveOutputCacheItem("foo/notifytasks/1/Status1");
works fine.

我希望这是你想要的。

这篇关于加入后的查询字符串打破RemoveOutputCacheItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 01:13