本文介绍了IhttpActionResult的ASP.NET Core Web Api错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试首次创建一个新的Core Web API应用.我正在使用Core 2.2
I am trying to create a new Core Web API app for the first time. I am using Core 2.2
我做了一些研究,但没有找到正确的答案.不知道我是否使用了错误的库.
I did some research but did not find the correct answer. Not sure if I am using wrong libraries.
不能将microsoft.aspnetcore.mvc.okresult类型隐式转换为system.web.http.Ihttpactionresult
cannot implicitly convert type microsoft.aspnetcore.mvc.okresult to 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 .
Core中不存在 IHttpActionResult 接口,它在较旧的Web API项目中使用.
The IHttpActionResult interface does not exist in Core, it's used in older Web API projects.
更多推荐
IhttpActionResult的ASP.NET Core Web Api错误
发布评论