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?
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
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
Well, I don't know what you're doing but it looks like something is messing with your routing (click for a larger version):
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
Thanks guys, it was a weird one, an IIS reset and a rebuild seems to have resolved it, was pulling my hair out :-)
Strange! Glad it's fixed :-)
is working on a reply...