I have two separated MVC applications and I want to deploy one of them under another one. I created a web site and an application in the ISS like "testsite1" and "testsite2". local.testsite1 is working very well but local.testsite1/testsite2 is not working because testsite1 is catching the request and trying to find a controller and throwing an exception. I do not want to create two different web site in IIS. How can I fix the problem?
2 Answers
0
votes
local.testsite1
and local.testsite1/testsite2
are the same domains. Not a sub-domain. Which means the application/IIS looking for the controller is the right behavior.
You may consider merging the sites in to one and use MVC Area to separate them? Also if you do not merge the site how will you Fire the app_start and other events separately for the sites?
In that case you can write custom routes separating the routes of testsite2 from testsite1.
For example route definition for testsite1 can be:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new string[] { "YourApp.Controllers" }
);
And your testsite2 area route registration can be:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
new { controller = "Branch|AdminHome|User" },
new[] { "YourApp.Areas.testsite2.Controllers" }
);
}
More about the implementation is here: Mvc area routing?