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

来源:互联网 发布:淘宝大码女装 编辑:程序博客网 时间:2024/04/30 04:25

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;     } }


0 0
原创粉丝点击