views:

439

answers:

2

I am looking for a solution to create subdomains pragmatically in ASP.NET, ASP.NET MVC and PHP. Specifically, a user profile page should resolve for both: www.domain.com/profilename or http://profilename.domain.com.

+3  A: 

Update your DNS settings of the particular domain so that *.domain.com all point to the same host.

Then, programmatically check and see if the first part of the URL used contains the subdomain you are looking for, and act accordingly. For example, if the first part contains a given profilename, then retrieve that particular profiles collection of data from your DB and display it to the user.

Make sure your web application uses relative links, so that if the user arrives at the site using a subdomain, that you don't redirect them elsewhere.

Sev
+1 catch-all domain is the way to go.
FreshCode
+1  A: 

There is no generic way to create subdomains. You will need to call an API provided by your ISP or DNS provider -- typically SOAP or REST.

Either that, or use a wildcard domain (*).

On the IIS side, be sure to configure you application so that it doesn't use Host headers.

RickNZ
Every site that does something like this uses wildcard domains. Actually creating individual DNS entries would mean long DNS propagation delays, insanely bloated zone files, etc.
Frank Farmer
It depends on how many subdomains you need (the OP didn't specify). Wildcarding is not always the best way to go, particularly if you're concerned about scalability. Here's a link to an example API for creating new subdomains, provided by a managed DNS service: https://durabledns.com/help/downloads/DurableDNS%20SOAP%20API%20Documentation%20v3.0.pdf
RickNZ