1

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 ?

Alex
  • 139
  • 10

1 Answers1

3

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.

Scott Forsyth
  • 16,339
  • 3
  • 36
  • 55
  • 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 Aug 19 '10 at 13:31