asp.net-core - IhttpActionResult 的 ASP.NET Core Web Api 错误

标签 asp.net-core asp.net-core-webapi

我第一次尝试创建一个新的核心 Web API 应用程序。我正在使用 Core 2.2

我做了一些研究,但没有找到正确的答案。不确定我是否使用了错误的库。

无法将类型 microsoft.aspnetcore.mvc.okresult 隐式转换为 system.web.http.Ihttpactionresult

这是我的代码

using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.AspNetCore.Mvc;

[Microsoft.AspNetCore.Mvc.Route("api/User")]
[ApiController]
public class UserController : ControllerBase
{
    [Microsoft.AspNetCore.Mvc.HttpGet]
    public async Task<IHttpActionResult> GetAllUsers()
    {
        var users = await this.GetUserAsync();
        return this.Ok(users);
    }
}

最佳答案

您需要使用IActionResult,而不是IHttpActionResult

IHttpActionResult 接口(interface)在 Core 中不存在,它在较旧的 Web API 项目中使用。

关于asp.net-core - IhttpActionResult 的 ASP.NET Core Web Api 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55029185/

相关文章:

mysql - 什么改变了 ASP.NET Core 连接字符串中的 "localhost"?

c# - 在单个 ASP.NET Core WebAPI 服务中托管多个产品 API

asp.net-core - 在 .net core web api 中发送自定义错误响应的最佳方法是什么

c# - ASP.NET Core Web API 中的过滤结果

c# - 一个 Web API Controller 来控制所有模型

c# - 从 Web API 核心下载文件 - Angular 7

asp.net - ASP.NET Core 中的 OAuth 授权服务

c# - MassTransit - 等待所有事件完成,然后继续处理

azure - Multi-Tenancy Azure B2C登录-如何获取外部用户电子邮件地址

c# - ASP.NET core中的kestrel服务器可以在启动时配置空闲超时吗