1. 程式人生 > >asp.net web api使用預設路由 put delete動作在IIS下受限

asp.net web api使用預設路由 put delete動作在IIS下受限

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