【发布时间】:2014-10-04 00:47:09
【问题描述】:
我有以下Action方法:-
[HttpGet]
[OutputCache(CacheProfile = "long", Location = OutputCacheLocation.Server, VaryByHeader = "X-Requested-With")]
public PartialViewResult LatestAssets()
{
var tech = repository.LatestTechnology().OrderByDescending(a => a.TechnologyID).Take(5).ToList() ;
return PartialView("_Latest",tech);
}
通过以下代码在_layout视图内部调用:-
<li class="nav-header hidden-tablet"style="background-color:#3E9BD4 ; color:white">Latest Assets</li>
@Html.Action("LatestAssets","Home")
缓存配置文件在 web.config 中定义如下:-
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="long" duration="300" />
<add name="Short" duration="100" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
但是当调用操作方法时我得到以下代码:-
持续时间必须是正数。描述:一个未处理的 执行当前 Web 请求期间发生异常。 请查看堆栈跟踪以获取有关错误的更多信息和 它起源于代码的地方。
异常详细信息:System.InvalidOperationException:持续时间必须是 一个正数
如果我删除了 CacheProfile,上述内容将正常工作。 知道是什么导致了这个错误。
【问题讨论】:
-
OutputCachefor ChildActions 不会遵守您个人资料的持续时间设置。您可以通过创建自定义 OutputCache 属性来绕过它以读取您的配置文件设置。方法如下:stackoverflow.com/a/13866280/1373170
标签: asp.net asp.net-mvc asp.net-mvc-3