I have an application using .NET Framework 4.7.1 with WebAPI and MVC routes defined in it. They both work when debugging locally with IISExpress, but when I deploy to the Development server (Windows Server 2012R2 with IIS 8.5), all I get is a 404.0 error for every route. I have put a static test.aspx file in the root folder of my IIS application and that returns correctly so it seems that IIS is just not picking up the routing. I have tried everything under the sun that I can Google and nothing has fixed it.
Here is my code for RouteConfig.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Here is my code for WebApiConfig.cs:
using System.Web.Http;
using System.Net.Http.Formatting;
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.IgnoreRoute("axd", "{resource}.axd/{*pathInfo}");
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.Clear();
config.Formatters.Add(new JsonMediaTypeFormatter());
// configure additional webapi settings here..
}
}
My Web.config includes the following:
<modules runAllManagedModulesForAllRequests="true"/>
<!-- Show detailed error messages -->
<httpErrors errorMode="Detailed" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
I have checked and .NET Framework 4.7.1 is installed on the server. Any help would be greatly appreciated.