views:

30

answers:

1

I have an MVC website which has 3 main components

  1. Member area which has the path /Member/{controller}/{action}/{id}
  2. Individual pages which will respond to any subdomain, e.g. user1.example.com/{controller}/{action}/{id}, user2.example.com/{controller}/{action}/{id}
  3. Main website which will respond to any url under www.example.com/{controller}/{action}/{id}

What is the easiest way to handle the routes that will allow the above 3 items to co-exist? I have tried many MapRoutes from the global.asax.cs file and also making a new class based on RouteBase but not having much luck.

+1  A: 

It sounds like you're heading in the right direction - essentially you need to create a custom route which looks at the request and constructs the route value dictionary. Rather than reinvent the wheel though, someone has already created a nice implementation which allows you to include placeholders in the domain itself like so:

routes.Add("DomainRoute", new  DomainRoute(
"{controller}.example.com",  "{action}/{id}",
new { controller = "Home", action = "Index", id = "" }));

http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx

FinnNk
I managed to get it working in the end using a mix of both techniques. Thanks!
Graeme