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;
}
}
可用于生成一个链接.

webapi中的Route的标签的命名参数name的使用的更多相关文章

  1. webapi中使用Route标签

    Prior to Web API 2, the Web API project templates generated code like this: protected void Applicati ...

  2. .NET中那些所谓的新语法之一:自动属性、隐式类型、命名参数与自动初始化器

    开篇:在日常的.NET开发学习中,我们往往会接触到一些较新的语法,它们相对以前的老语法相比,做了很多的改进,简化了很多繁杂的代码格式,也大大减少了我们这些菜鸟码农的代码量.但是,在开心欢乐之余,我们也 ...

  3. 【AspNetCore】【WebApi】扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat)

    扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat) 一.背景 大家在使用WebApi时,会用到DateTime为参数,类似于这 ...

  4. HTML标签的命名/CSS标准化命名大全

    在一个内容较多的HTML页面中,需要设计许多不同的框架,再为这些不同的框架及内容进行分类,给予相应的名称,从而使得网页结构更加清晰,也为工作提供了方便.许多新手朋友在设计一个HTML文件时,可能只会依 ...

  5. .NET Core WebApi中实现多态数据绑定

    什么是多态数据绑定? 我们都知道在ASP.NET Core WebApi中数据绑定机制(Data Binding)负责绑定请求参数, 通常情况下大部分的数据绑定都能在默认的数据绑定器(Binder)中 ...

  6. .net WebApi中使用swagger生成WepApi集成测试工具

    我在WebApi中使用swagger的时候发现会出现很多问题,搜索很多地方都没找到完全解决问题的方法,后面自己解决了,希望对于遇到同样问题朋友有帮助.我将先一步一步的演示项目中解决swagger遇到问 ...

  7. WebApi中的参数传递

    在WebApi开发过程中,遇到一些客户端参数格式传输错误,经常被问到参数如何传递的一些问题,因此就用这篇博客做一下总结,肯定其它地方呢也有类似的一些文章,但是我还是喜欢通过这种方式将自己的理解记录下来 ...

  8. ASP.NET Core WebAPI中使用JWT Bearer认证和授权

    目录 为什么是 JWT Bearer 什么是 JWT JWT 的优缺点 在 WebAPI 中使用 JWT 认证 刷新 Token 使用授权 简单授权 基于固定角色的授权 基于策略的授权 自定义策略授权 ...

  9. 沉淀,再出发:sublime中快捷键和html标签的使用和生成以及使用markdown

    沉淀,再出发:sublime中快捷键和html标签的使用和生成以及使用markdown 一.前言 工欲善其事,必先利其器.在软件代码的编写中,一定要知道IDE或者编辑器的快捷键的使用,这样可以提高很多 ...

随机推荐

  1. Unity启动事件-监听:InitializeOnLoad

    [InitializeOnLoad] :在启动Unity的时候运行编辑器脚本  官方案例: using UnityEngine; using UnityEditor; [InitializeOnLoa ...

  2. JsSIP.UA.JsSIP 总是返回错误:422 Session Interval Too Small

    在JsSIP 中 JsSIP.UA.call 总是 返回错误:422 Session Interval Too Small 关于错详情在这篇文章中解释的比较详尽:http://www.cnblogs. ...

  3. ios UIImageView异步加载网络图片

    方法1:在UI线程中同步加载网络图片 UIImageView *headview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 4 ...

  4. java 随机生成11位 组合

    public static String generate8RateUuid() {          String[] chars = new String[] { "a", & ...

  5. Postman怎么用?

    国庆期间的工作就是搞清楚postman怎么用?

  6. html的简单表单制作...day5 php

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. mvc前端样式自定义

    1.别忘记加 htmlAttributes @Html.EditorFor(model => model.Quantity, new { htmlAttributes = new { @clas ...

  8. 集成shareSDK的微信、QQ API导致cocoaPods找不到类symbol问题的解决方法

    因为shareSDK的微信和QQ API都只支持32位的,而cocoaPods默认要支持64位的,所以如果在工程中导入这两个API会出问题. 解决方法我就不转载啦,原文在这里: http://blog ...

  9. iOS Plugins

    iOS Plugins This section provides details for how to implement native plugin code on the iOS platfor ...

  10. 新服务器sudo与权限分配<NIOT>

    0,生成RSA公钥秘钥 a,源主机:#ssh-keygen -t rsa 1,拷贝公钥到authorized_keys文件里面 a,源主机:#ssh-copy-id -i /root/.ssh/id_ ...