IHttpActionResult vs IActionResult

17,421

Solution 1

IHttpActionResult is for ASP.NET Web Api, while IActionResult is for ASP.NET Core. There's no such thing as "Web Api" in ASP.NET Core. It's all just "Core". However, some people still refer to creating an ASP.NET Core API as a "Web Api", which adds to the confusion.

Solution 2

It depends on what version of ASP.NET you are going to use. That can either be the .NET Core version or the traditional one.

As mentioned by Chris you can only use IActionResult in ASP.NET Core:

https://docs.microsoft.com/en-us/aspnet/core/web-api/action-return-types?view=aspnetcore-2.1#iactionresult-type

I'm creating an API

Well, if you are using the traditional ASP.NET - instead of .NET Core you are fine with using IHttpActionResult: https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/action-results, otherwise stick with IActionResult.

Share:
17,421
Guilherme Ferreira
Author by

Guilherme Ferreira

Updated on June 15, 2022

Comments

  • Guilherme Ferreira
    Guilherme Ferreira almost 2 years

    I'm creating an API using .NET Core 2 to provide data for many applications developed in different technologies. I'm currently returning IActionresult from my methods. I've been studying what the best option is to return the data and saw some examples using IHttpActionResult. Now I dont't know which type is the best to return.

    What is the difference between IHttpActionResult and IActionresult?