ASP.NET MVC makes it easy to create a custom route handler in the Global.asax.cs file:
routes.MapRoute( "Default", "{controller}.aspx/{action}/{id}", new { action = "Index", id = "" } ).RouteHandler = new SubDomainMvcRouteHandler();
This will cause all requests to be processed by the custom RouteHandler user. For this specific handler:
public class SubDomainMvcRouteHandler : MvcRouteHandler { protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext) { return new SubDomainMvcHandler(requestContext); } }
Then you can do whatever you want, in this case SubDomainMvcHandler grabs the subdomain from the URL and passes it to the controller as a property:
public class SubDomainMvcHandler : MvcHandler { public SubDomainMvcHandler(RequestContext requestContext) : base(requestContext) { } protected override void ProcessRequest(HttpContextBase httpContext) {
Jason
source share