Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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:

domain.com/bob

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 ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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

 
discard

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.