Due to various engineering requirements, I need to develop a new ASP.NET Web API application (called BarApp) in the same application domain of an existing application (called FooApp).
I would like to configure an ASP.NET Web API application (BarApp) as a virtual directory within an existing ASP.NET MVC application (FooApp) in IIS 8.5. Although many posts talked about how to set up a virtual directory, none of them work.
Below is a snippet of configuration
<site name="FooApp" id="3" serverAutoStart="true">
<application path="/" applicationPool="FooApp">
<virtualDirectory path="/" physicalPath="E:\FooApp" />
<virtualDirectory path="/Bar" physicalPath="E:\BarApp" />
</application>
<bindings>
<binding protocol="https" bindingInformation="*:34566:" sslFlags="0" />
</bindings>
</site>
Here is the site structure:
-FooApp
|
|
|
|
|
|
|
In a Foo application, I configured routing: add an access route for the entire path using Bar
--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 }
);
}
}
}
- WebApiConfig, save the automatically generated file.
namespace FooApp
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
In BarApp, the routing configuration changes as:
--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)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "Bar/api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
, , , .
Bar: https://mywebsite.test.com:4433/Bar/
HTTP 403.14 -
- , .
- API: https://mywebsite.test.com:4433/Bar/api/values
HTTP 404.0 -
, , , .
-API 2.2.1