Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

API Routing Problem, 200 in dev, but 404 on servers

$
0
0

So my project is using MVC 5 with Web API 2.2, Entity Framework, and AngualarJS.  I have about a dozen API Controllers that are working perfectly in my dev environment, but when I published the application to the server, which is using IIS 7, I always get a 404 error for all of my APIs.  When debugging on my localhost, fidder will report my host is “localhost:6215” and URL is “/api/personnel/” … this is works perfectly!  Now when I publish the web application to “http://www.testApp.com/InternalProfile/” and navigate to this site, fidder reports that my host is “www.testApp.com” and URL that fiddler retrieves is “/api/personnel/” and returns a 404 error because "InternalProfile" isn't included.  But when I navigate within the browser tohttp://www.testApp.com/InternalProfile/api/Personnel/, the JSON is return back perfectly, the problem is the routing piece never including “InternalProfile” when published.  Also, I don't want to hard code "InternalProfile" in neither, because potentially the name of the site could change from InternalProfile to something else.  What am I missing from the following code?

// In my Global.asax.cs Application_Start method
GlobalConfiguration.Configure(WebApiConfig.Register);
// Within WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
   config.MapHttpAttributeRoutes();
}
// Within the Personnel API Controller
[HttpGet]
[Route("api/personnel")] public IHttpActionResult GetPersonnel() { List<Personnel> personnel = new List<Personnel>(); // Fill personnel object return Ok(personnel); }
// My AngularJS function call to the Personnel API.
getPersonnel: function () {
   return $http.get("api/personnel/")
      .then(function (response) {
         return response.data;
      });
};

I would greatly appreciate help with this problem that has had me stuck for while.  Thanks!


Viewing all articles
Browse latest Browse all 4850


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>