Copied to clipboard

Flag this post as spam?

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


  • Chris Lord 15 posts 51 karma points
    May 14, 2014 @ 18:00
    Chris Lord
    0

    API and Surface Controllers

    Trying to create an API controller but getting 404 error when accessing URL

    public class CustomController : UmbracoApiController

    {

    [System.Web.Http.HttpGet]
    public IEnumerable<string> GetAllProducts()
    {
    return new [] {"Table", "Chair"};
    }

    }

    I thought I could then access the URL using /umbraco/api/Custom/GetAllProducts but get 404.

    Also have same issue with surface controllers, for example;

    public class LoginController : SurfaceController

    {

    [System.Web.Http.HttpGet]
    public int Index()
    {
    return 1;
    }

    }

    /umbraco/surface/Login/Index gives me a 404.

    I am surely missing something simple here, it's been one of those days, so any clues would be really appreciated. Tried running in IIS Express and IIS same issue, surely a config thing, I have the training site I did in training (v 7.0.4) which is working ok? I understand I shouldn't need to create any custom routes or anything like that?

    Version 7.1.2

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    May 14, 2014 @ 20:04
    Sebastiaan Janssen
    0

    Well, I don't know what you're doing but it looks like something is messing with your routing (click for a larger version):

    enter image description here

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    May 14, 2014 @ 20:08
    Marc Goodson
    0

    If it's any consolation for your sanity the code seems fine!, I just cut and paste your controller code above into a fresh 7.1.2, rebuilt and you can see from screen grab returns data ok. did you get 7.1.2 via Nuget ? or upgrade or is it a fresh download. If you've used Nuget or upgraded, I'd check global.asax exists and is inheriting Umbraco.Web.UmbracoApplicationsax.cs 

  • Chris Lord 15 posts 51 karma points
    May 15, 2014 @ 10:39
    Chris Lord
    0

    Thanks guys, it was a weird one, an IIS reset and a rebuild seems to have resolved it, was pulling my hair out :-)

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    May 15, 2014 @ 10:53
    Sebastiaan Janssen
    0

    Strange! Glad it's fixed :-)

  • 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