asp.net-core – MVC 6 Web Api:解析201上的位置标题(已创建)

在Web Api 2.2中,我们可以通过从控制器返回来返回位置标头URL,如下所示:
return Created(new Uri(Url.Link("GetClient",new { id = clientId })),clientReponseModel);

Url.Link(..)将根据控制器名称GetClient相应地解析资源URL:

在ASP.NET 5 MVC 6的Web Api中,Url在框架中不存在,但CreatedResult构造函数确实具有location参数:

return new CreatedResult("http://www.myapi.com/api/clients/" + clientId,journeyModel);

如何在不必手动提供此URL的情况下解析此URL,就像我们在Web API 2.2中所做的那样?

解决方法

我没有意识到,但CreatedAtAction()方法满足于此:
return CreatedAtAction("GetClient",new { id = clientId },clientReponseModel);

确保您的控制器派生自MVC的Controller.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...