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