I'm working on an ASP.NET MVC Multi Tenancy app.

Right now I managed to create dynamic subfolders, for instance some one registers with username "bob" and gets the following website:


My next goal is to provide subdomains: bob.domain.com instead of subfolders.

I found out that it's very complex to create dynamic subdomains with ASP.NET and DNS WMI. Is there a way to tell the server that it has to redirect/rewrite from bob.domain.com to domain.com/bob ?


You can create a wildcard entry for *.domain.com so that you don't need to create a DNS entry on every new account.

You can add a wildcard IIS binding too so that everything for a particular IP will bind to that site. That you don't need to add tons of host headers in real-time.

URL Rewrite is one option for doing what you requested. You can watch for {HTTP_HOST} with the pattern of ^(^.)+.domain.com$. That will get everything.domain.com with a back reference of C:1.

Or, another option is to just check for Request.ServerVariables["HTTP_HOST"] from MVC directly. You have full access to the domain name from code, so you have a lot of flexibility there.

  • Thanks for your answer! The problem is when I create the *.domain.com entry in DNS server, I still can't access random.domain.com (subdomain that doesn't exist). I get no server found error, so I can't use Request.ServerVariables["HTTP_HOST"]. – Alex Aug 19 '10 at 11:38
  • Never mind, I just had to add *.domain.com binding in IIS. Thanks! – Alex Aug 19 '10 at 12:56
  • Excellent, glad you got it working. – Scott Forsyth - MVP Aug 19 '10 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.