ASP.NET核心中的IHttpActionResult和Helper方法 [英] IHttpActionResult and helper methods in ASP.NET Core

查看:16
本文介绍了ASP.NET核心中的IHttpActionResult和Helper方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的Web API 2项目移动到ASP.NET5。 但我有许多不再存在的元素。

例如IHttpActionResultOk(), NotFound()方法。 或RoutePrefix[]

是否应将IHttpActionResult更改为IActionResult? 是否将Ok()更改为new ObjectResult?(是否相同?)

HttpConfiguration似乎不再出现在Startup.cs中的HttpConfiguration怎么办?

推荐答案

IHttpActionResult现在是有效的IActionResult,要使用返回对象返回Ok,可以使用return new ObjectResult(...);

所以实际上是这样的:

public IActionResult Get(int id)
{
    if (id == 1) return HttpNotFound("not found!");
    return new ObjectResult("value: " + id);
}

这里有一篇更详细的好文章:

http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6

这篇关于ASP.NET核心中的IHttpActionResult和Helper方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆