Yes, it should be possible to do this. I can think of one way; there may be others.
The first step is to modify the default route to include your application name:
routes.MapRoute("Default",
"{applicationName}/{controller}/{action}/{id})",
null, null);
I'm presuming that you're going to group the two "applications" into different namespaces within a single assembly. So you might have two namespaces like:
- MyApp.Blog.Controllers
- MyApp.Forum.Controllers
Next, you need to change the controller factory so that it instantiates the right controller. You can do this by subtyping the DefaultControllerFactory and overriding the GetControllerType method:
protected override System.Type GetControllerType(string controllerName)
{
string applicationName;
if (RequestContext != null &&
RequestContext.RouteData.Values.TryGetValue(
"applicationName", out applicationName)) {
// return controller type using app name to
// look up namespace and controllerName argument
return ...
}
// if no match, maybe it's a different controller/route
return base.GetControllerType(controllerName);
}
Finally, you need to tell MVC to use your ControllerFactory. In Global.asax.cs:
private void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
ControllerBuilder.Current.SetControllerFactory(
MyApp.MyControllerFactory());
}
Locating views can be handled similarly. In this case, you subtype WebFormViewEngine.