MVC3 HttpStatusCodeResult在OnActionExecuted中不起作用

时间:2011-02-24 16:40:35

标签: c# .net asp.net-mvc http asp.net-mvc-3

我有以下代码使用新的MVC3 HttpStatusCodeResult:

  protected override void OnActionExecuted(ActionExecutedContext filterContext) {
        base.OnActionExecuted(filterContext);
        filterContext.Result = new HttpStatusCodeResult(304, "Not Modified");
  }

我仍然得到200OK,我无法弄清楚为什么。请指教。

1 个答案:

答案 0 :(得分:7)

适合我:

public class HomeController : Controller
{
    protected override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        base.OnActionExecuted(filterContext);
        filterContext.Result = new HttpStatusCodeResult(304, "Not Modified");
    }

    public ActionResult Index()
    {
        return View();
    }
}

结果就是我们所期望的:

enter image description here