views:

26

answers:

2

I have noticed that ASP.NET MVC 3 introduces a HttpStatusCodeResult action result. How do we do the equivalent in ASP.NET MVC 2? I want to return a 410 code.

+1  A: 

You could create your own HttpStatusCodeResult which might look something like this:

public class HttpStatusCodeResult : ActionResult
{
    private readonly int code;
    public HttpStatusCodeResult(int code)
    {
        this.code = code;
    }

    public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
    {
        context.HttpContext.Response.StatusCode = code;
    }
}
Matthew Manela