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!
or change
[HttpGet] to be explicitly [System.Web.Http.HttpGet]
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.
Umbraco 8: Two controllers with same method named Ping. The requested resource does not support http method 'GET'
I have 2 controllers:
Both have the same method:
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?
Hi Nikhil
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!
or change
[HttpGet] to be explicitly [System.Web.Http.HttpGet]
to be super sure.
regards
Marc
Hi Marc,
Yes the namespace was wrong. I changed it to
using System.Web.Http;
and marked the controller methods with
[System.Web.Http.HttpGet]
Its working now. Thanks.
Why have the same attribute in 2 namespaces?
Nikhil
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.
regards
marc
is working on a reply...