1

I am developing CMS system and my problem is than with MVC i will use subdomain. www.domain1.example.com www.domain2.example.com and etc goes to 800 subdomains. Custom Route is one of the solution but all websites not will be same as design, they will be independent as design. So what is the best way to do it fast enough.

Thanks in advance

  • Possible duplicate of [Asp.net mvc 301 redirect from www.domain.com to domain.com](http://stackoverflow.com/questions/2175975/asp-net-mvc-301-redirect-from-www-domain-com-to-domain-com) – ViVi Dec 16 '16 at 08:24

1 Answers1

0

One approach would be to use a custom route constraint as here: https://www.asp.net/mvc/overview/older-versions-1/controllers-and-routing/creating-a-custom-route-constraint-cs

You then use this to turn on and off certain routes from your route table dependent on the subdomain (which you can inspect in the route constraint code).

routes.MapRoute(
            "Admin",
            "Admin/{action}",
            new { controller = "Admin"},
            new { subdomainMatch = new SubdomainCriterion(SubdomainGroup.GroupA) }
        );

So in this example, this route would only work for Group A of subdomains.

You could do this better in ASP.Net Core which has a much more flexible routing system, where you could have a completely different routing table for each subdomain or group of subdomains. Its more complex conceptually and a little difficult to follow, but very powerful. You can read about this here:

http://stephenwalther.com/archive/2015/02/07/asp-net-5-deep-dive-routing

James Ellis-Jones
  • 3,042
  • 21
  • 13