I have a problem that's driving me nuts.
I have a basic web api written in C# / web API 2 on .net 4.5. As long as I deploy the site to the root directory of IIS 7.5, it works fine - as soon as I deploy it to a sub directory, I get 404 errors for any method requests.
my setup is this:
I have a single controller called ServicesController with the following methods:
public IEnumerable<Service> GetAllServices()
{
return Services;
}
public IHttpActionResult GetService(int id)
{
var Service = Services.FirstOrDefault((p) => p.Id == id);
if (Service == null)
{
return NotFound();
}
return Ok(Service);
}
}
}
I have a routing template set like this:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
if I check the request in fiddler as it's coming through, on the root directory (root directory being localhost, or wwwroot) the request looks right:
api/services/1 (for example)
In the sub directory (called ServicesApp), the request prepends the directory name, which (I think?) may be the problem (or not), like this:
ServicesApp/api/services/1
Is there something I need to change in my visual studio project settings to modify the base call, or could it be something else? I'm a bit of a web api 2 novice, so I'm sure it's something small I'm missing.
Other things I've tried based on other posts I've read here:
-iis integrated mode is enabled in my web.config
-i did try adding runAllManagedModulesForAllRequests option in web.config as well
I can create a sub application in IIS and define the sub directory as the root, and it'll work fine, but that's not a viable option since this is going to be deployed to a remote / shared windows host that doesn't allow that level of functionality.
Any help greatly appreciated. Apologies in advance if I missed an obvious answer while searching.