Adding WebAPI as a Child / Nested Application in IIS

Steps to recreate this problem:

  • Inside IIS, create a new .net 4 website (hereinafter referred to as the parent). Take the test image in the folder for this website and note that you can request it successfully in the browser
  • Add a new virtual directory OR an application under the parent that points to the WebAPI 2 project
  • Attempting to access the API in a browser using www.path-to-parent-site.com/api/something/or/other

I get the following error:

System.Web.Routing.UrlRoutingModule does not implement IHttpHandlerFactory or IHttpHandler. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Configuration.ConfigurationErrorsException: System.Web.Routing.UrlRoutingModule does not implement IHttpHandlerFactory or IHttpHandler. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [ConfigurationErrorsException: System.Web.Routing.UrlRoutingModule does not implement IHttpHandlerFactory or IHttpHandler.] System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +12328272 System.Web.Configuration.HandlerFactoryCache..ctor(String type) +27 System.Web.HttpApplication.GetFactory(String type) +94 System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +375 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34209 

Is there anything I can do to make this work? I can find very little relevant information on this particular problem and even fewer solutions for those who saw this error.

Note. If I add the WebAPI 2 project as a new website in IIS, it works fine; its only when it is nested as a child (either a virtual directory or an application has the same problem) that this happens.

thanks

+7
iis asp.net-web-api asp.net-web-api2
source share
2 answers

WebApi should not be located in a virtual directory, if you want to do this, you need to make a dynamic routing template and download the first part from the virtual directory.

 var virtualDirectory = request.ApplicationPath; routes.MapHttpRoute( name: "API Default", routeTemplate: virtualDirectory + "/api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); 
0
source share

You should use parentsite.com/childvirtualdirectory/api , even if the API is in childvirtualdirectory .

In my scenario, I had the parentsite/api setting in IIS ... then to access the web API I needed to use http://parentsite/api/api/<<controller>>

0
source share

All Articles