Route Names

In Web API, every route has a name. Route names are useful for generating links, so that you can include a link in an HTTP response.

To specify the route name, set the Name property on the attribute. The following example shows how to set the route name, and also how to use the route name when generating a link.


public class BooksController : ApiController
{
[Route("api/books/{id}", Name="GetBookById")]
public BookDto GetBook(int id)
{
// Implementation not shown...
} [Route("api/books")]
public HttpResponseMessage Post(Book book)
{
// Validate and add book to database (not shown) var response = Request.CreateResponse(HttpStatusCode.Created); // Generate a link to the new book and set the Location header in the response.
string uri = Url.Link("GetBookById", new { id = book.BookId });
response.Headers.Location = new Uri(uri);
return response;
}
}
可用于生成一个链接.

最新文章

  1. JavaScript权威设计--Window对象之Iframe(简要学习笔记十四)
  2. 安装lxml时gcc: internal compiler error: Killed (program cc1)的解决方法
  3. 完美解决AutoCAD2012,AutoCAD2013本身电脑里有NET4.0或以上版本却装不上的问题
  4. hdu Line belt
  5. quotas and disk replace on netapp
  6. android 自动化压力测试-monkey 3 命令参数
  7. Devexpress之barManager控件属性
  8. [置顶] 如何在Windows 7 64位安装Python,并使用Matplotlib绘图
  9. C++ do while 0 使用和含义
  10. pandas 使用
  11. (NO.00003)iOS游戏简单的机器人投射游戏成形记(九)
  12. WebApiClient库支持AOT
  13. Storage 002 电商数据库设计
  14. OneNote中添加代码问题
  15. Spark思维导图之性能优化
  16. vue 在.vue文件里监听路由
  17. Centos7 Crontab
  18. Learning-Python【29】:网络编程之粘包
  19. 1.5eigen中高级初始化
  20. 关于几个vcenter的合并心得!

热门文章

  1. C# 语言规范_版本5.0 (第21章 附录C_参考资料)
  2. C#深复制与浅复制
  3. B+树概念学习
  4. [学习笔记]agileone安装登陆报错,localhost重定向次数过多
  5. 修改searchBar的返回按钮的显示文字
  6. idea不能加载xml
  7. CSS继承性+层叠性+盒子+浮动
  8. vb.net 结束进程
  9. Redis 的几种数据结构&五种数据类型对象
  10. LeetCode 319. Bulb Switcher