Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikhil 38 posts 129 karma points
    1 week ago
    Nikhil
    0

    Umbraco 8: Two controllers with same method named Ping. The requested resource does not support http method 'GET'

    I have 2 controllers:

    1. AController : UmbracoApiController
    2. BController : UmbracoApiController

    Both have the same method:

    [HttpGet]
    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?

  • Marc Goodson 1247 posts 8423 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    100

    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

  • Nikhil 38 posts 129 karma points
    1 week ago
    Nikhil
    0

    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

  • Marc Goodson 1247 posts 8423 karma points MVP 5x c-trib
    1 week ago
    Marc Goodson
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft