对于以下两个控制器,/api/container/dasdada
返回“a”。如果我这样做,container?value=hello
我会得到“你好”。什么会导致参数绑定不起作用?
public HttpResponseMessage Get()
{
return Request.CreateResponse<string>("a");
}
public HttpResponseMessage Get(string value)
{
return Request.CreateResponse<string>(value);
}
我正在使用 Katana 来托管它:
HttpConfiguration apiConfig = new HttpConfiguration();
apiConfig.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
apiConfig.Formatters.Remove(apiConfig.Formatters.XmlFormatter);
apiConfig.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
app.UseDependencyResolver(resolver)
.UseWebApiWithOwinDependencyResolver(resolver, apiConfig);
app.UseWebApi(apiConfig);