Wildcard Subdomains in MVC5 and Azure WebApp

If you’re here, I’m going to assume you already know what Wildcard Subdomains are.  The point of this post is to teach you how to get them to work in your MVC application, both on your dev machine, and on Azure WebApps.

First step is to get it working on your local machine.  Ben Cull does a great job of getting this working over at his blog: http://benjii.me/2015/02/subdomain-routing-in-asp-net-mvc/  I highly recommend watching his short video on the topic also: https://youtu.be/dMFOo0__rm0

The only problem I ran into at this point was that I would get an exception that the controller wasn’t defined if the URL looked like “subdomain.localhost:4353”.  So, I just added an IF blocks to his SubdomainRoute class to make ‘controller’ “Home” if it is an empty string, and an IF block to make ‘action’ “Index” if it is an empty string.

After this, everything works perfect locally.

To get this to work in Azure WebApps, however; you need to complete a couple more steps.

First, you’ll need to go to your domains DNS management and add the following CNAME record:


This gets a Value which looks something like this (Azure will tell you what it needs to be)


Next, in Azure, go to your WebApp and click “Configure” and then scroll down and click “Manage Domains”.  Here, you’ll add the following domain name:


Note: This is where Azure will tell you what to put in your CNAME record.

You’re all set.  Now you can go to “AnySubdomainThatYouWant.YourDomain.Com” and it should work!