In a WEB API controller, can we have the same method name with different HTTP Verbs?
[HttpGet]
public string Test()
{
return "Success Get";
}
[HttpPost]
public string Test(int i)
{
return "Success Post";
}
Swagger does not accept this configuration. I get this error when accessing the API methods:
500 : "Message":"An error has occurred.","ExceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Common' and method 'POST'. See the config setting - \"ResolveConflictingActions\" for a potential workaround"
Here is my routeconfig:
config.Routes.MapHttpRoute(
name: "DefaultApiByName",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiByAction",
routeTemplate: "api/{controller}/{action}"
);
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id=RouteParameter.Optional});