是否可以在mvc JsonResult控制器方法上使用OutputCache?

st7*_*t78 13 asp.net-mvc json outputcache

我试图这样做,它导致contentlen 0的结果

看起来像:

[OutputCache(Duration = 36000)]
public JsonResult GetFileClasses() 
{
   return this.Json(TopicConfig.FileExtensionsSettings.List)
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Bra*_*nov 15

OutputCacheAttribute你还必须指定,VaryByParam参数.否则,您将在结果处理中获得此异常System.Web.HttpException: The directive or the configuration settings profile must specify the 'varyByParam' attribute. 您可以尝试添加此参数并查看它是否有效.

  • 澄清:`[OutputCache(Duration = 36000,VaryByParam ="")]`.谢谢Branislav,这也让我疯了! (5认同)