我正在使用.net Web API V1构建一些休息的api.
我们正在尝试为web api定义一些路由.我在定义“Put”和“patch”的路线时遇到一些问题.
他们有相同的URL,唯一不同的是在HttpMethod.在HttpMthod中,不支持补丁http://msdn.microsoft.com/en-us/library/system.net.http.httpmethod(v=vs.118).aspx
config.Routes.MapHttpRoute( "UpdateCustomer","api/customers/id/{id}",new {controller = "Customers",action = "UpdateCustomer"},new {id = @"\d+",httpMethod = new HttpMethodConstraint(HttpMethod.Put)} ); config.Routes.MapHttpRoute( "PatchCustomer",action = "PatchCustomer"},httpMethod = new HttpMethodConstraint(HttpMethod.**Patch**)} );
解决方法
改用:
新的HttpMethod(“PATCH”)
请参阅Web API源代码中的以下示例使用
http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Http/HttpPatchAttribute.cs