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; } }
时间: 2024-11-08 21:39:14