Chris Kooken
Chris Kooken

Reputation: 33948

MVC3 HttpStatusCodeResult Not working in OnActionExecuted

I have the following code which uses the new MVC3 HttpStatusCodeResult:

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

I am still getting a 200OK and I can't figure out why. Please advise.

Upvotes: 1

Views: 868

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039598

Works for me:

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();
    }
}

And the result is what we would expect:

enter image description here

Upvotes: 7

Related Questions