Hello,
I am working on a simple MVC2 multi-tenant application. My question is how do I determine which tenant portal has been asked for in the url by the user? What I need to have happen is this:
- A request to http://localhost should go to the standard Home controller’s index page
- A request to http://localhost/client1 should go to the ClientPortalHome controller’s index page
- A request to http://localhost/client1/LogOn will go to the client specific logon page
The two routes below achieve this and seem to work fine.
routes.MapRoute(
"Client Portal Default", // Route name
"{clientportal}/{controller}/{action}/{id}", // URL with parameters
new { controller = "ClientPortalHome", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults,
);
My question is how do I determine which client portal has been asked for (client1 in the above example)?
I tried using this:
private void Application_BeginRequest(Object source, EventArgs e)
{
var route = RouteTable.Routes.GetRouteData(new HttpContextWrapper(Context));
var currentPortal = route.GetRequiredString("clientportal");
Context.Items.Add("ClientPortalName", currentPortal);
}
The problem is that it is called for all routes and throws an exception for the Home controller case because the route does not contain a “clientportal” entry.
What’s the best way to determine which portal has been requested so I can make sure it exists and show the client specific home page? Do I need a custom route handler?
Thank you in advance.
Rick