Reputation: 15415
I am looking for implementation options how to handle requests with more exotic HTTP verbs like PROPFIND
or MKCOL
with ASP.NET Core or ASP.NET Core MVC.
In ASP.NET Core MVC you can decorate your action methods with
[HttpGet]
[HttpPut]
[HttpPost]
[HttpDelete]
[HttpHead]
[HttpOptions]
[HttpPatch]
For a REST API or web applications these HTTP verbs are sufficient. For WebDav for example PROPFIND
or MKCOL
verbs have to be handled somehow, too.
Is there a possibility to extend ASP.NET Core MVC to support more HTTP verbs than the ones listed above ? Or do you think that writing an own middleware component is the better approach to add WebDav capabilities to a ASP.NET Core app ?
I have looked into the ASP.NET Core Source Repositories to get some ideas. But I am stuck in the moment.
Upvotes: 4
Views: 1823
Reputation: 15415
The solution is easier than I thought. You can invoke Controller Actions by a HTTP verb like this
public class WebDavController : Controller
{
[HttpGet]
[Route("/dav/{fileName}")]
public IActionResult Get(string fileName)
{
// a classic Get method
....
}
[Route("/dav/{fileName}")]
public IActionResult Propfind(string fileName)
{
// this is invoked if http verb is PROPFIND
// (framework searches for corresponding action name)
....
}
[AcceptVerbs("LOCK")]
[Route("/dav/{fileName}")]
public IActionResult MyLockAction(string fileName)
{
// this is invoked if http verb is LOCK
// (framework searches annotated action method)
....
}
}
Upvotes: 7