【发布时间】:2015-12-03 18:48:01
【问题描述】:
如何使用 outputcache 缓存自定义错误页面?
自定义错误页面:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/customerror/notfound" responseMode="ExecuteURL" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" path="/customerror/servererror" responseMode="ExecuteURL" />
</httpErrors>
自定义错误控制器:
public class CustomErrorController
{
[OutputCache(Duration = duration, Location = OutputCacheLocation.Server, VaryByHeader = "Host", VaryByParam = "None")]
public ActionResult NotFound()
{
return this.View("NotFound", this.Build());
}
private TestModel Build()
{
var model = new TestModel
{
Header = GetSiteHeaderContent(SiteId),
Footer = GetSiteFooterContent(SiteId),
Navigations = GetNavigations(),
SecondaryNavigations = GetSecondaryNavigation()
};
return model;
}
}
问题是动作从未被缓存,尽管我在很多地方都使用了输出缓存并且工作正常。
注意:我使用的是 Memcached。
提前致谢。
【问题讨论】:
标签: asp.net caching asp.net-mvc-5 memcached