Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: 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 to ?

share|improve this question
up vote 3 down vote accepted

You can create a wildcard entry for * 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 ^(^.)$. That will get 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.

share|improve this answer
Thanks for your answer! The problem is when I create the * entry in DNS server, I still can't access (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 * 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 posting your answer, you agree to the privacy policy and terms of service.

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