Copied to clipboard

Flag this post as spam?

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


  • Russell McGinnis 48 posts 183 karma points
    Aug 07, 2014 @ 20:41
    Russell McGinnis
    1

    Web Api 405 Method Not Allowed

    I am trying to use the Web Api process for Ajax in Umbraco 7 but getting a 405 Method Not Allowed error.

    My js code is:

    jQuery.getJSON('/Umbraco/Api/SignUp/SignUp/', { Firstname: jQuery('#Firstname').val() })

                    .done(function (data) { 

                    });

    And my controller is:

        public class SignUpController : UmbracoApiController {

            public JsonResult SignUp(string Firstname) {

                Dictionary<string, object> results = new Dictionary<string, object>();

                results.Add("success", true);

                JsonResult res = new JsonResult();

                res.Data = results;

                return res;

            }

        }

    I am tearing what hair I have out trying to track this down... it has to be obvious!
    Russell
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 07, 2014 @ 20:46
    Jeavon Leopold
    103

    Try to rename your method to GetSignUp and then request /Umbraco/Api/SignUp/GetSignUp/

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 07, 2014 @ 20:50
    Jeavon Leopold
    0

    Or add the [HttpGet] attribute to your method, e.g.

    [HttpGet]
    public JsonResult SignUp(string Firstname) {
    
  • Russell McGinnis 48 posts 183 karma points
    Aug 07, 2014 @ 20:56
    Russell McGinnis
    0

    Jeavon, thanks again for saving me. I renamed the method in the controller to GetSignUp and it all worked great.

    Is there something that Umbraco is doing under the covers here ? Or is it part of WebApi ?

     

    Thanks again.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 07, 2014 @ 21:01
    Jeavon Leopold
    3

    Hi Russell,

    It's WebApi native here, with the prefix "Get" it allows get requests or you can decorate your method with the [HttpGet] attribute I posted above.

    I remember going through exactly the same pain the first time I created a WebApi controller :-)

    Jeavon

  • Alberto Leon 2 posts 23 karma points
    Feb 18, 2021 @ 07:47
    Alberto Leon
    1

    I know this is old, but I added the attribute HttpGet at that didn't fix it. Just rename with Get in front of it.

  • David Walker 19 posts 90 karma points
    Nov 10, 2021 @ 09:22
    David Walker
    0

    Had this exact problem too when trying to run with an api tutorial in V8. Wondered if this was governed by a setting somewhere either in IIS or Umbraco somewhere :/

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies