Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have 2 controllers:
Both have the same method:
public async Task<string> Ping()
The first controller works i.e. https://localhost/umbraco/Api/A/Ping
The second one https://localhost/umbraco/Api/B/Ping throws the error: The requested resource does not support http method 'GET'.
Why does the second one not work?
There are two implementations of HttpGet!!
One for MVC Controllers in System.Web.Mvc.HttpGet and one for Web Api Controllers in System.Web.Http.HttpGet
My guess is that in the controller that 'doesn't work' you've accidentally resolved [HttpGet] to come from the System.Web.Mvc namespace and not the System.Web.Http one...
So have a look at the using statements in your controller that doesn't work to see if you have using System.Web.Mvc and revert it to be System.Web.Http to see if it works!
[HttpGet] to be explicitly [System.Web.Http.HttpGet]
to be super sure.
Yes the namespace was wrong. I changed it to
and marked the controller methods with
Its working now. Thanks.
Why have the same attribute in 2 namespaces?
Just to annoy you? :-P
It's because System.Web.MVC existed first and when they came to build the WebApi much later on they didn't want to make it wholly dependent on the System.Web.MVC namespace...
... or at least that's the explanation I remember.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted