Why is the ExecuteResult () method not being called in ASP.NET Web API 2?

I am creating some custom actions as shown below.

public class MyActionResult : ActionResult
{
    public override void ExecuteResult(ControllerContext context)
    {
        context.HttpContext.Response.Status = "my status";
        context.HttpContext.Response.StatusCode = 400;
        context.HttpContext.Response.AppendHeader("MyHeader", "bingo");
        context.HttpContext.Response.Write("some content");
        context.HttpContext.Response.End();
    }
}

      

And my action method looks like this:

[HttpGet]
[Route("check/{id}")]
public MyActionResult Check(string id)
{
    return new MyActionResult();
}

      

I set a breakpoint in ExecuteResult (), but it never hit. And I am testing web API like this:

http://localhost:22247/api/v1/check/123

      

I was expecting to see the content, title, etc. that I have set in the ExecuteResult () method. But the actual result is always a JSON file with empty content as shown below. And the status code is always 200.

{}

      

Why is the ExecuteResult () method not executing?

+3


source to share


1 answer


The Web API borrowed some ideas from ASP.NET MVC and duplicated some of the type names from the ASP.NET MVC namespaces. But the Web API is a completely different beast from ASP.NET MVC. They should not be used in a naive way.



+2


source







All Articles