It seems ASP.NET implicitly interprets method named GetX
and PostX
as GET and POST methods respectively, because of their names are prefixed with HTTP method names. This is also the case for PUT and DELETE.
I have a method unfortunately named Delete
but I want it to be interpreted as a POST, so I explicitly specify it's a POST using the [HttpPost]
attribute. This works, as long as it's not declared inside an interface...
public interface IFooBarController
{
[HttpPost]
void DoSomething();
[HttpPost]
void Delete(int id);
}
public class FooBarController : IFooBarController
{
public void DoSomething()
{
// This API method can only be called using POST,
// as you would expect from the interface.
}
public void Delete(int id)
{
// This API method can only be called using DELETE,
// even though the interface specifies [HttpPost].
}
}
How can I work around this, without having to specify the HttpPostAttribute for each implementation?