1

We have the following three external visible 'endpoints'

  • api.domain.com
  • demo.domain.com
  • my.domain.com

We're using MVC5 and ideally we'd like to steer each of the above sub-domains into it's own area (per MVC terminology).

i.e.

  • api.domain.com => route into WebAPI (as a separate 'area'? Not sure)
  • demo.domain.com => route to 'demo' area
  • my.domain.com => route to 'my' area
  • support.domain.com => route to 'support' area (and so on)

However, I couldn't find a way to configure this. Does anyone know how we can setup the above?

The end goal is to have all the above as a single MVC site that we can deploy to Azure Cloud Services.

DeepSpace101
  • 13,110
  • 9
  • 77
  • 127
  • Are you looking for a server side redirect, e.g. have the browser address bar still show demo.domain.com, but have the server work out of the demo area directory; or a client-side redirect where browser address bar shows domain.com/demo/? – zomf Jul 14 '14 at 23:34

2 Answers2

2

Did you look into Url Rewriting? if you are using IIS then you can download url rewrite Module and then in web.config you can do something like this:

<rewrite>
   <rules>
      <rule name="Rewrite sub-domain to dir" enabled="true">
         <match url="^(.*)$" />
         <conditions>
            <add input="{HTTP_HOST}" pattern="^subdomain\.domain\.co\.uk$" />
         </conditions>
         <action type="Rewrite" url="subdomain/{R:1}" />
      </rule>
   </rules>
</rewrite>

Source: http://www.azurecurve.co.uk/2011/12/how-to-rewrite-a-sub-domain-to-a-directory-in-iis/

highwingers
  • 1,649
  • 4
  • 21
  • 39
-2

refer to the answer at Mvc area routing?

The answerer's example for an area under the /Admin/ folder is:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional },
        new { controller = "Branch|AdminHome|User" },
        new[] { "MyApp.Areas.Admin.Controllers" }
    );
}
Community
  • 1
  • 1
ps2goat
  • 8,067
  • 1
  • 35
  • 68