Is there any way to route based on the HTTP method specified in the request? I'm looking to have a GET and PUT at the same URI, but I can't seem to find the option to set the route between the two. The [HttpGet] and [HttpPut] attributes merely act as filters, so a PUT request is hitting the first action and erroring out with a 405 since it hits the GEt handler first.
What I want to do
~/User/PP GET -> UserController.GetPrivacyPolicy
~/User/PP PUT -> UserController.UpdateUserPrivacyPolicy
Whats currently happening
~/User/PP GET -> UserController.GetPrivacyPolicy
~/User/PP PUT -> UserController.GetPrivacyPolicy
(this errors out because i have a [HttpGet] filter on the GetPrivacyPolicy method)
Update: Just to compliment what was posted below, it looks like I misunderstood how the [HttpGet] and [HttpPut] attributes work, they ARE part of the routing process. I was able to achieve my desired result with the following
[HttpGet]
[Route("~/User/PP")]
public string GetPrivacyPolicy()
{
return "Get PP";
}
[HttpPut]
[Route("~/User/PP")]
public void UpdatePrivacyPolicy()
{
return "Put PP";
}