I want to create sub domains on the fly for each of my identity users (AspNetUsers). You can see this kind of feature available in blogger.com.
I have list of sub domain names in the database
Users={"abc", "xyz","blah"}
My original website is like this
http://mywebsite.com
The above users should access my website like below
http://abc.mywebsite.com
http://xyz.mywebsite.com
http://blah.mywebsite.com
I can do this in the web.config for the above 3 users. But users table will change frequently. So I would like to create sub domains on the fly for each user available in the Users
table.
How can we achieve this using Asp.Net MVC?
Maarten Balliauw has posted an excellent solution with a downloadable demo to this issue titled ASP.NET MVC Domain Routing. Note that the demo doesn't upgrade correctly to recent versions of Visual Studio, but there aren't many files that are required to use this method so reverse engineering is not that painful.
DomainRoute.cs
DomainData.cs
LinkExtensions.cs
Edit to Global.asax (or in more recent versions of MVC, these go into
AppStart\RouteConfig.cs
)Also see a gist with this solution (and discussion) here.