<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg" -->

---
title: ASP.NET MVC Domain Routing | daily.dev
description: A custom DomainRoute class extends ASP.NET MVC's routing engine to support tokenized subdomain routing, addressing limitations in the default...
canonical: https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: ASP.NET MVC Domain Routing | daily.dev
og:description: A custom DomainRoute class extends ASP.NET MVC's routing engine to support tokenized subdomain routing, addressing limitations in the default...
og:url: https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg
og:image: https://api.daily.dev/og/posts/LpkMHu6FG.png
og:image:alt: ASP.NET MVC Domain Routing
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# ASP.NET MVC Domain Routing

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 6 min read · 0 upvotes · 0 comments

## Summary

A custom DomainRoute class extends ASP.NET MVC's routing engine to support tokenized subdomain routing, addressing limitations in the default System.Web.Routing infrastructure where only URL path tokens are used, not domain tokens. The approach supports scenarios like multilingual subdomains, multi-tenant client subdomains, and controller-mapped subdomains, while also fixing URL generation issues (VirtualPathData) that plagued an earlier community solution. Full source code with HtmlHelper extension methods is provided for download.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2009-05-20-aspnet-mvc-domain-routing>

## Questions this post answers

### How do I implement subdomain routing in ASP.NET MVC where the subdomain contains tokens like {controller} or {language}?

Create a custom route class that extends the base Route class and overrides GetRouteData to match both the request's host header and URL path against separate regex patterns built from domain and path token templates. Route values are extracted from matched regex groups for both domain and path, supporting patterns like {controller}.example.com or {language}.example.com combined with {action}/{id} paths.

_daily.dev surfaces practical routing patterns for developers building multi-tenant or multilingual ASP.NET apps._

### Why do ActionLink helpers generate incorrect URLs when using custom subdomain routing in ASP.NET MVC?

ActionLink helpers generate broken URLs because the ASP.NET MVC routing infrastructure's VirtualPathData class only considers tokens within the URL path, not the domain portion, so values meant for the subdomain get appended as query string parameters instead, producing URLs like live.localhost/Home/Index/?liveMode=false instead of develop.localhost/Home/Index. Overriding GetVirtualPath to strip domain tokens before calling the base implementation and adding custom ActionLink extension methods that inject the correct hostname fixes this.

_developers debugging malformed MVC-generated URLs can find grounded fixes like this through daily.dev._

## Similar posts on daily.dev

- [URL Pattern Matching in .NET](https://daily.dev/posts/url-pattern-matching-in-net-eoobxiadc) · Meziantou · 29 upvotes · 4 comments
- [ASP.NET Core Controllers: A Practical Guide to Building REST Endpoints](https://daily.dev/posts/asp-net-core-controllers-a-practical-guide-to-building-rest-endpoints-qbrdx5rqi) · We Are .NET · 0 upvotes · 0 comments
- [How to Upgrade ASP.NET MVC to .NET Step by Step](https://daily.dev/posts/how-to-upgrade-asp-net-mvc-to-net-step-by-step-i3p1uesfs) · C\# Corner · 2 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#), [#multi-tenancy](https://daily.dev/tags/multi-tenancy)

[View this post on daily.dev](https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"ASP.NET MVC Domain Routing","url":"https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg"},"datePublished":"2026-10-04T13:05:34.229Z","dateModified":"2026-10-04T13:08:28.219Z","description":"A custom DomainRoute class extends ASP.NET MVC's routing engine to support tokenized subdomain routing, addressing limitations in the default...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6e442a301e6515145a4cc5c4ae005a71?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6e442a301e6515145a4cc5c4ae005a71?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net,c#,multi-tenancy","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"ASP.NET MVC Domain Routing"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/asp-net-mvc-domain-routing-lpkmhu6fg#faq","mainEntity":[{"@type":"Question","name":"How do I implement subdomain routing in ASP.NET MVC where the subdomain contains tokens like {controller} or {language}?","acceptedAnswer":{"@type":"Answer","text":"Create a custom route class that extends the base Route class and overrides GetRouteData to match both the request's host header and URL path against separate regex patterns built from domain and path token templates. Route values are extracted from matched regex groups for both domain and path, supporting patterns like {controller}.example.com or {language}.example.com combined with {action}/{id} paths. daily.dev surfaces practical routing patterns for developers building multi-tenant or multilingual ASP.NET apps."}},{"@type":"Question","name":"Why do ActionLink helpers generate incorrect URLs when using custom subdomain routing in ASP.NET MVC?","acceptedAnswer":{"@type":"Answer","text":"ActionLink helpers generate broken URLs because the ASP.NET MVC routing infrastructure's VirtualPathData class only considers tokens within the URL path, not the domain portion, so values meant for the subdomain get appended as query string parameters instead, producing URLs like live.localhost/Home/Index/?liveMode=false instead of develop.localhost/Home/Index. Overriding GetVirtualPath to strip domain tokens before calling the base implementation and adding custom ActionLink extension methods that inject the correct hostname fixes this. developers debugging malformed MVC-generated URLs can find grounded fixes like this through daily.dev."}}]}
```

