当控制器操作返回 RedirectResult 结果时,输出缓存过滤器似乎不适用。
以下是如何重现 ASP.Net MVC3 默认 Internet Web 应用程序的问题:
在 Web.config 中:
<system.web>
<caching>
<outputCache enableOutputCache="true"></outputCache>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ShortTime" enabled="true" duration="300" noStore="false" />
</outputCacheProfiles>
</outputCacheSettings>
</caching> ...
Run Code Online (Sandbox Code Playgroud)
在 HomeController.cs 中:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcOutputCacheRedir.Controllers
{
public class HomeController : Controller
{
[OutputCache(CacheProfile = "ShortTime")]
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
[OutputCache(CacheProfile = "ShortTime")]
public ActionResult About()
{
// Output cache works as expected …Run Code Online (Sandbox Code Playgroud)