title: Configure ASP.NET Web API application as a Virtual Directory under ASP.NET MVC application
body: <p>Due to various engineering requirements, I need to develop a new ASP.NET Web API application (named as  BarApp) within the same Application domain of an existing application (named as FooApp).</p>
  
  <p>I would like to configure an ASP.NET Web API application (BarApp) as a virtual directory under an existing ASP.NET MVC application (FooApp) on IIS 8.5. Though many many posts talked about how to configure a virtual directory, none of them work. </p>
  
  <p>Here is the configuration snippet</p>
  
  <pre><code>        &lt;site name="FooApp" id="3" serverAutoStart="true"&gt;
              &lt;application path="/" applicationPool="FooApp"&gt;
                  &lt;virtualDirectory path="/" physicalPath="E:\FooApp" /&gt;
                  &lt;virtualDirectory path="/Bar" physicalPath="E:\BarApp" /&gt;
              &lt;/application&gt;
              &lt;bindings&gt;
                  &lt;binding protocol="https" bindingInformation="*:34566:" sslFlags="0" /&gt;
              &lt;/bindings&gt;
          &lt;/site&gt;
  </code></pre>
  
  <p>Here is the website structure:</p>
  
  <pre><code>-FooApp
  |
  |--Bin
  |--View
  |--Bar (as a virtual directory)
      |
      |--Bin
      |--View   
  </code></pre>
  
  <p>In the Foo App, I configured the routing: add an ingore route for all path with Bar</p>
  
  <pre><code>--RouteConfig.cs
    namespace FooApp
    {
         public class RouteConfig
         {
            public static void RegisterRoutes(RouteCollection routes)
           {
               routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
               routes.IgnoreRoute("{*path}", new { path = @"Bar\/(.*)" });
  
               routes.MapRoute(
                  name: "Default",
                  url: "{controller}/{action}/{id}",
                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
               );
           }
     }
  }
  </code></pre>
  
  <p>--WebApiConfig, keep the automatically generated one.</p>
  
  <pre><code> namespace FooApp
   {
      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 }
              );
            }
       }
  }
  </code></pre>
  
  <p>In the BarApp, the routing configure is modified as:</p>
  
  <pre><code>--RouteConfig.cs
  namespace BarApp
  {
      public class RouteConfig
      {
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                 name: "Default",
                 url: "Bar/{controller}/{action}/{id}",
                 defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
              );
           }
       }
  }
  
  --WebApiConfig
  namespace BarApp
  {
     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: "Bar/api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
        }
     }
  }
  </code></pre>
  
  <p>However, the above configuration does not work, and the ignore route seems not taken into effect.<br>
  Failed to access page of Bar: <a href="https://mywebsite.test.com:4433/Bar/" rel="noreferrer">https://mywebsite.test.com:4433/Bar/</a>
  HTTP Error 403.14 - Forbidden
  The Web server is configured to not list the contents of this directory.</p>
  
  <p>Failed to access Web API of Bar: <a href="https://mywebsite.test.com:4433/Bar/api/values" rel="noreferrer">https://mywebsite.test.com:4433/Bar/api/values</a> 
  HTTP Error 404.0 - Not Found
  The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.</p>
  
  <p>the  Web API library is 2.2.1</p>