Trying to host locally a rest service in IIS. Everything works fine in IIS Express but as soon as I try to host locally in IIS the routing doesn't work.
- It's compiled to x86 and is hosted inside of an app pool that allows for 32 bit processes.
- I have the site mapped to the binary output folder from my build
msbuild /p:Configuration=Release /p:ProcessorArchitecture=x86 -r:False
- I have
Anonymous Authentication
enabled - Binding is type
http
to port 8000 - I have enabled directory browsing and see the below at
http://localhost:8000/
- However whenever I try to navigate to
http://localhost:8000/api/HeartBeat
I get a404 - Not Found
.
My WebApiConfig class which sets a default route.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Here is the controller
public class HeartBeatController : ApiController
{
// GET: api/HearBeat/5
public HttpResponseMessage Get()
{
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
If I run this in IIS Express and navigate to that same url I get a 200. Also I've tried to examine the URL in powershell using Get-WebUrl
and it shows a ProtocolError but I have no clue what or why. And IIS Manager doesn't seem to complain about anything.
PS C:\Windows\system32> Get-WebURL -PSPath "IIS:\Sites\Test" | Format-list
Status : ProtocolError
ResponseUri : http://localhost:8000/
Description : Forbidden
CodePudding user response:
A couple of things were amiss.