---
title: "Asp.net mvc route based on subdomain"  
description: "Asp.net mvc route based on subdomain"  
author: "Anonymous User"  
published: 2014-10-07  
updated: 2014-10-07  
canonical: https://www.mindstick.com/forum/2329/asp-dot-net-mvc-route-based-on-subdomain  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# Asp.net mvc route based on subdomain

Is it possible to have an [ASP.NET MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) [route](https://www.mindstick.com/interview/396/what-is-routed-event-in-wpf) that uses subdomain information to determine its route? For example.

· user1.domain.com goes to one place

· user2.domain.com goes to another?

Or, can I make it so both of these go to the same [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc)/[action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) with a [username](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username) [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp)?

## Replies

### Reply by Anonymous User

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)                    return null;                 var subDomain = url.Substring(0, index);                 if (subDomain == "user1")                {                    var routeData = new RouteData(this, new MvcRouteHandler());                    routeData.Values.Add("controller", "User1");                    routeData.Values.Add("action", "Index");                     return routeData;                }                 if (subDomain == "user2")                {                    var routeData = new RouteData(this, new MvcRouteHandler());                    routeData.Values.Add("controller", "User2");                    routeData.Values.Add("action", "Index");                     return routeData;                }                 return null;            }             public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)            {                return null;            }        }
```


---

Original Source: https://www.mindstick.com/forum/2329/asp-dot-net-mvc-route-based-on-subdomain

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
