views:

25

answers:

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 ?

+2  A: 

In regards to routing based on subdomain, you should reference the following SO post.

*Sorry, I normally don't like to just link to an answer, but in this case, I don't want to take the credit from the original poster for the solution

EDIT

Check out solution 2 to follow up on my comments below as a working example. You can ignore the ISAPI rewrite as the MVC routing engine would do this for you given the above solution from SO. Below is a snippet that you might find useful:

Setup DNS Server

Add the following entry into your DNS server and change the domain and IP address accordingly.

*.example.com IN A 1.2.3.4 Setup the Web Server

We are assuming that you already have a web site created for your main site: www.example.com. So let's just double check to make sure it will be able to accept all variations of the subdomains.

* Open IIS Management Console and select your web site.
* Right click on it and select Properties.
* Click on Web Site tab.
* Click on Advanced button.
* Make sure there is one entry under the Multiple identities for this

Web Site with Host Header Name field blank. This entry will intercept all requests that comes to this IP address. * Make sure the IP address is only used by this web site.

Tommy
Thanks for the link, but they guy has static domains that exist and are processed by the DNS server. I want to use dynamic domains.
Alex
Did you see my comment on your question above? You don't have to register every single user subdomain in DNS. Have your wildcard for your domain point to your webserver. So mail.domain.com would still point to your mail server (given that is a defined entry in DNS) but someRandomString.domain.com would go to your webserver. From there, determine if it is an valid directory(redirect) or not (throw up a 404).
Tommy
Thanks! Looks like that's exactly what I need. I haven't tried it yet, because I don't have access to the server, but when I do, I'll let you know.
Alex