Copied to clipboard

Flag this post as spam?

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


  • Nikhil 54 posts 166 karma points
    Sep 16, 2020 @ 14:39
    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 2126 posts 14217 karma points MVP 8x c-trib
    Sep 17, 2020 @ 05:48
    Marc Goodson
    101

    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 54 posts 166 karma points
    Sep 17, 2020 @ 08:54
    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 2126 posts 14217 karma points MVP 8x c-trib
    Sep 17, 2020 @ 12:55
    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