3
看来outputcache过滤器在控制器操作返回RedirectResult结果时不适用。OutputCache不缓存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> ...
在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
// return View();
// Output cache has no effect
return Redirect("Index");
}
}
}
我无法在任何地方找到此行为......这是正常的吗?如果是这样,任何解决方法?
我希望Http内容能被缓存它是一个200或302状态码......谢谢 – 80n