webapi中常用attribute标签
HTTP Methods
Instead of using the naming convention for HTTP methods, you can explicitly specify the HTTP method for an action by decorating the action method with the HttpGet, HttpPut, HttpPost, or HttpDelete attribute.
In the following example, the FindProduct method is mapped to GET requests:
public class ProductsController : ApiController
{
[HttpGet]
public Product FindProduct(id) {}
}
To allow multiple HTTP methods for an action, or to allow HTTP methods other than GET, PUT, POST, and DELETE, use the AcceptVerbsattribute, which takes a list of HTTP methods.
public class ProductsController : ApiController
{
[AcceptVerbs("GET", "HEAD")]
public Product FindProduct(id) { } // WebDAV method
[AcceptVerbs("MKCOL")]
public void MakeCollection() { }
}
Routing by Action Name
With the default routing template, Web API uses the HTTP method to select the action. However, you can also create a route where the action name is included in the URI:
routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
In this route template, the {action} parameter names the action method on the controller. With this style of routing, use attributes to specify the allowed HTTP methods. For example, suppose your controller has the following method:
public class ProductsController : ApiController
{
[HttpGet]
public string Details(int id);
}
In this case, a GET request for “api/products/details/1” would map to the Details method. This style of routing is similar to ASP.NET MVC, and may be appropriate for an RPC-style API.
You can override the action name by using the ActionName attribute. In the following example, there are two actions that map to "api/products/thumbnail/id. One supports GET and the other supports POST:
public class ProductsController : ApiController
{
[HttpGet]
[ActionName("Thumbnail")]
public HttpResponseMessage GetThumbnailImage(int id); [HttpPost]
[ActionName("Thumbnail")]
public void AddThumbnailImage(int id);
}
Non-Actions
To prevent a method from getting invoked as an action, use the NonAction attribute. This signals to the framework that the method is not an action, even if it would otherwise match the routing rules.
// Not an action method.
[NonAction]
public string GetPrivateData() { ... }
webapi中常用attribute标签的更多相关文章
- HTML_body中常用的标签部分
meta: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <t ...
- css中常用的标签
最常用的标签 left 左 top 上 right 右 bottom 下 font 字体 size 大小 width 宽度 height 高度 class 类 label 标签 form 表单 gro ...
- HTML5中常用的标签(及标签的属性和作用)
1.标签:<!DOCTYPE>作用:声明是文档中的第一成分,位于<html>标签之前. 2.标签:<html>作用:此元素可告知浏览器其自身是一个HTML文档.属性 ...
- Liferay JSP中常用的标签
(本文转载自http://www.cnblogs.com/edwardlauxh/archive/2010/03/26/1918614.html) 在Liferay框架中拥有它自身的标签,虽然Port ...
- html5 中常用的标签和属性
标签: <blockquote> 标签定义摘自另一个源的块引用. <blockquote> 与 </blockquote> 之间的所有文本都会从常规文本中分离出来, ...
- jsp中常用的标签
jsp本质上就是一个servlet,只是tomcat会将其翻译成servlet,servlet本质上是一个类,那么jsp也是一个类.jsp中各种标签都会被tomcat翻译成各种基本的java代码 如果 ...
- html中常用的标签元素
<html></html> 创建一个HTML文档<head></head> 设置文档标题和其它在网页中不显示的信息<title></t ...
- webapi中使用Route标签
Prior to Web API 2, the Web API project templates generated code like this: protected void Applicati ...
- html中常用的标签小结
内容详细标签: <h1>~<h6>标题标签<pre>格式化文本<u>下划线(underline)<i>斜体字(italics)<cit ...
随机推荐
- 130道C#面试题
C#/.Net/数据库笔试资料C#资料(一)1.静态成员和非静态成员的区别?答:静态变量使用 static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明的变量称做 ...
- Centos7下建立rubymine快捷方式到侧栏或桌面
gnome桌面的所有菜单项都存储如下位置: /usr/share/applications/ 新建一个菜单项,直接在该目录下新建一个后缀名为.desktop的文件即可. $ vi /usr/share ...
- 安装Genymotion与集成eclipse,最后有集成android studio
本安装过程从不用到VPN 一切国内网络都可以解决. 首先下载Genymotion,网址 https://www.genymotion.com/account/login/ 首先需要注册,我使用163 ...
- svn客户端的安装与中文版本语言库
首先在mac下下载svn或者其他软件请看另一篇博客链接:http://www.cnblogs.com/minyc/p/myc201606191543.html 另附svn常用命令操作详解:http:/ ...
- Linux Curl常用命令使用【转】
Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1)读取网页 $ curl linuxidc.com">http://www.linuxidc.com 2)保存 ...
- 第一百二十五节,JavaScript,XML
JavaScript,XML 学习要点: 1.IE中的XML 2.DOM2中的XML 3.跨浏览器处理XML 随着互联网的发展,Web应用程序的丰富,开发人员越来越希望能够使用客户端来操作XML技术. ...
- Zsh安装
Zsh 使用 Homebrew 完成 zsh 和 zsh completions 的安装 brew install zsh zsh-completions 安装 oh-my-zsh 让 zsh 获得拓 ...
- PHP短信发送服务 youe短信企业服务
/** * 通用短信平台HTTP接口POST方式发送短信实例 * 返回字符串 * 一般情况下调用此方法 */ function postSendMessage($msgContents,$phoneL ...
- iherb账户
LMJ997 23622335@qq.com yjxwly***** LUR472 13821660226@163.com linda**** LFW887 bella****
- selenium1,selenium2,watir的比较
接触web方面的自动化测试,会接触几个常用的工具,selenium1,selenium2,watir 有的时候总是混淆,那么他们的优缺点啥的呢,在让你给项目选自动化框架,会选择哪个??? 1,语言的支 ...