Home  /  Questions  /  Question

66   95.8
Apr 18, 2011

Programmatically create subdomains on IIS with ASP.NET MVC

So, here are my requirements. I am building a multi-tenant site where companies after they sign up get their own subdomain.
Assume that my business is called Email Jobs Inc with domain www.emailjobs.com.  This site is hosted in a shared ISP environment so I have very limited access to IIS etc.

Just to clarify, here is an example of what I need:

company1 signs up and they get this url  company1.emailjobs.com
company2 signs up and they get this url  company2.emailjobs.com
company3 signs up and they get this url: company3.emailjobs.com

My understanding is that there is a DNS and IIS component to this. That is, I will need to change an entry in a DSN server and then also a binding in IIS.  All this is very tricky, because of non-static IP addresses, etc. etc.

However, another option I heard of is to ask your ISP to setup an IIS wildcard option where *.emailjobs.com goes straight to my ASP.NET MVC server. There I can parse the URL, extract the subdomain and I would be in business!  Right?  

Could someone confirm that this is possible and correct? 

I realize that another option I have is to build urls like this: www.emailjobs.com/company1 etc, but that would be far less elegant.
Any feedback would be greatly appreciated...


50   50
Apr 21, 2011
I guess you are on right track...see this for setting up zone at DNS server using wildcard


this way you get all incoming requests for
 company2.emailjobs.com and so on to a specific website created on IIS - make sure you dont have host header with website name and only with IP address.

And use IIS redirect or MVC or traditional web form to intercept request at code level and serve request...

Happy programming