【发布时间】:2011-11-04 17:07:52
【问题描述】:
当控制器操作返回 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");
}
}
}
我在任何地方都找不到这种行为……这正常吗?如果是这样,有什么解决方法吗?
【问题讨论】:
标签: asp.net-mvc outputcache response.redirect