IHttpActionResult vs IActionResult
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
:
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
.
Guilherme Ferreira
Updated on June 15, 2022Comments
-
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 usingIHttpActionResult
. Now I dont't know which type is the best to return.What is the difference between
IHttpActionResult
andIActionresult
?