views:

49

answers:

2

How to implement a mechanism (within a single ASP.NET MVC application) to ensure that:

  • if request comes on mydomain (user visits mydomain.com) -> handle using certain set of controllers
  • if request comes on otherdomain (user visits otherdomain.com) -> handle using different set of controllers

(the domains are aliased to the same web hosting)

What extension points within ASP.NET MVC should I use to ensure that the described mechanism works?

A: 

Why not set up 2 web applications that share common code in a DLL? Each web app would be a standard MVC application.

chris166
there is no common code to share between the applications - the point is to serve multiple applications within a single ASP.NET MVC "container" deployed on a shared web hosting
Marek
+1  A: 

I think you could implement a IRouteConstraint descendant that analyzes the current HttpContext and matches (or does not match) a route depending on the domain requested. Then have two different default routes in your Global.asax file, each with different constraints.

I would still prefer two applications, but it's your choice of course.

Adrian Grigore
Thanks, I think this is what I have been looking for. I'd prefer two apps as well, but this will not be my decision to take :)
Marek