Is it possible to make an ASP.NET MVC route based on a subdomain?

You can do it by creating a new route and adding it to the routes collection in RegisterRoutes in your global.asax. Below is a very simple example of a custom Route: public class ExampleRoute : RouteBase { public override RouteData GetRouteData(HttpContextBase httpContext) { var url = httpContext.Request.Headers[“HOST”]; var index = url.IndexOf(“.”); if (index < 0) … Read more

Why map special routes first before common routes in asp.net mvc?

The routing engine will take the first route that matches the supplied URL and attempt to use the route values in that route. The reason why this happens is because the RouteTable is used like a switch-case statement. Picture the following: int caseSwitch = 1; switch (caseSwitch) { case 1: Console.WriteLine(“Case 1”); break; case 1: … Read more

Multiple levels in MVC custom routing

You can make CMS-style routes seamlessly with a custom RouteBase subclass. public class PageInfo { // VirtualPath should not have a leading slash // example: events/conventions/mycon public string VirtualPath { get; set; } public Guid Id { get; set; } } public class CustomPageRoute : RouteBase { private object synclock = new object(); public override … Read more