加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-web-api – ASP.NET Core中的IHttpActionResult和帮助程

发布时间:2020-12-16 00:34:02 所属栏目:asp.Net 来源:网络整理
导读:我试图将我的web api 2项目移动到ASP.NET 5。 但我有很多不再存在的元素。 例如IHttpActionResult或Ok(),NotFound()方法。 或RoutePrefix [] 应该用IActionResult更改每个IHttpActionResult? 用新的ObjectResult更改Ok()? (是一样吗?) HttpConfiguration
我试图将我的web api 2项目移动到ASP.NET 5。
但我有很多不再存在的元素。

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

应该用IActionResult更改每个IHttpActionResult?
用新的ObjectResult更改Ok()? (是一样吗?)

HttpConfiguration在startup.cs中似乎没有什么呢?

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读