您的位置:首页 > 编程语言 > ASP

asp.net web api使用默认路由 put delete动作在IIS下受限

2014-12-18 11:04 537 查看
asp.net web api使用默认路由

1. put、delete动作在IIS中受限(可通过remove
WebDAV,方法见上一篇)

2.每个controller可写action有限,在单个业务操作较多的情况下需要建立多个controller

使用新路由,仅使用Get、Post动作

protected void Application_Start(object sender, EventArgs e) {
var config = GlobalConfiguration.Configuration;
var routes = config.Routes;
routes.MapHttpRoute(
"DefaultHttpRoute",
"api/{controller}/{action}/{id}",
new { id = RouteParameter.Optional }
);
}


public class TestController : ApiController {
[HttpGet]
public string[] List() {
return new string[] {"a","b","c" };
}

[HttpGet]
[HttpPost]
public string[] Detail(string id) {
return id;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐