1

I'm having an issue making a Web API call from an angular/hottowel app where the Web API controller is using attribute-based routing. I'm currently wondering if angular is interfering but, honestly, I have no idea how to confirm.

My service method looks like this:

function getAllOrganizations() {
    return $http.get('api/organizations').then(function (result) {
        return result.data;
    });
}

It's returning a 404 when it's called:

GET http://localhost/admin/api/organizations 404 (Not Found)

I should mention at this point that the app is hosted in a virtual directory 'admin'. Checking my routes with routes.axd, it looks ok to me (Methods = GET, HEAD, OPTIONS, Url = api/organizations etc.), matching my method/attribute (I have tried this both with and without a leading '/' with no effect):

[GET("/api/organizations")]
[HttpGet]
public string GetAllOrganizations()
{
    return "it worked";
}

Any ideas what is going on? What other information would be useful?

UPDATE
Switching back to IIS Express caused an eeor along the lines of:

"The constraint entry 'inboundHttpMethod' on the route with route template 'api/Contacts/{id}' must have a string value or be of a type which implements 'IHttpRouteConstraint'

Having fixed that with help from here, running this in IIS Express works.

(And, in a subsequent test, moving the app to be it's own website also makes it start working...)

So it seems there is an issue, maybe, with attribute-based routing in a virtual directory - does that ring a bell?

Community
  • 1
  • 1
Michael
  • 4,010
  • 4
  • 28
  • 49
  • It seems that 'http://localhost/admin/api/organizations' is a 404 because of the admin part of the route. Could you post more info about your structure? – David East Mar 18 '14 at 20:55
  • Use POSTMan (chrome plugin) to test the back-end separately from the front-end this will make it easier to debug. – shaunhusain Mar 18 '14 at 20:57
  • Good eye - I've ammended the question to explain that 'admin' is the virtual directory in which the site is hosted. – Michael Mar 18 '14 at 20:58
  • @shaunhusain - POSTMan also reported a 404. – Michael Mar 18 '14 at 22:22
  • Okay well that eliminates the Angular portion at least for the time being, until you can get the request working with curl or POSTMan or something like that needn't worry about the client side code just yet. Unfortunately I know nothing about ASP.net or configuring the server aside from Apache/PHP/Java/Spring stuff so you'll need to have someone else chime in to help out here. – shaunhusain Mar 18 '14 at 22:40
  • You can verify if it's because of the subdomain if you'd run it without on a server (or your local host). We are currently facing the same problem; works locally not on sub application in IIS. Hoping some knows an elegant solution. (Fiddler is also great checking the backend if you don't want to run chrome plugin). – NP83 Jun 17 '14 at 09:25

0 Answers0