VaryByParam不使用参数,仅*

时间:2013-02-06 20:43:09

标签: ajax json model-view-controller outputcache

我已经看过其他VaryByParam问题了,但我还没有找到问题的答案。我有一个MVC网站,其中定义了以下操作:

[OutputCache(Duration = 30, VaryByParam = "TargetID")]
public JsonResult IsThingAllowed(int TargetID)
{
    bool isAllowed = IsAllowed(TargetID);

    return Json(isAllowed, JsonRequestBehavior.AllowGet);
}

无论TargetID是什么,都会返回缓存的值。但是,如果我将TargetID更改为*,则按预期工作(缓存值因TargetID而异):

[OutputCache(Duration = 30, VaryByParam = "*")]

这是AJAX的电话:

$.ajax({
    url: "/MyController/IsThingAllowed",
    type: "POST",
    data: JSON.stringify({ "TargetID": id }), // This is definitely varying!
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (data, textStatus, xhr) {

        updateThing(data);
    },
    error: function (xhr, textStatus, error) {

    }
});

当参数明确命名时,我做错了什么?

编辑:如果我们使用GET代替POST,则可以工作..但POST显然有效,因为它适用于我们使用*

此处使用GET

 $.ajax({
     url: "/MyController/IsThingAllowed",
     type: "GET",
     data: { TargetID: id },
     dataType: "json",
     contentType: "application/json; charset=utf-8",
     success: function (data, textStatus, xhr) {

         updateThing(data);
     },
     error: function (xhr, textStatus, error) {

     }
 });

0 个答案:

没有答案
相关问题