views:

586

answers:

6

How can I create a subdomain in an asp.net C# application? I am working with an asp.net portal. In that portal I need to be able to create the subdomain at runtime. The ftp for that subdomain also needs to be the same as the main domain ftp.

A: 

subdomain's are controlled by your dns settings. Beyond that I can't understand your question.

whatsisname
A: 

I think the best way is to have a wildcard DNS entry - i.e. *.domain.com that points to the domain. And then use a rewriting tool, like helicontech.com, to rewrite the 1st part of the subdomain to tell your app what you're looking at.

This would use regular expressions to pass the subdomain to your app:

RewriteCond Host: (mysub).domain.com RewriteRule (.*) /$2?subdomain=$1 [I,L,U]

NickAtuShip
A: 

There are two halves to this: A) Changing your DNS Settings: This varies based on your host and whatnot. Contact them and ask if you can't figure it out.

B) Changing your host settings: This varies based on your server. I assume you're using some version of IIS.

In IIS6, you can right click a web site, select the properties page, go to the web site tab, select advanced in web site identification, and start adding bindings (Generally you'll use default or the ip address for IP Address, 80 for TCP Port (unless SSL), and the site for the host header file (e.g. www.example.com or subdomain.example.com).

In IIS7, you right click on a website and select edit bindings, then click "Add". IIS7's add screen is pretty self explanatory.

Brian
+4  A: 

There are a handful of working parts here. It sounds like the requirement is that this all happen at runtime. I am sure a lot of web hosting providers are deep into these sets of problems and likely have custom solutions.

DNS: you'll need to have an API open at the DNS host. If it's a LAN environment, you'll have to check your DNS provider on whether they have APIs exposed. (i.e. Windows Server or whatever your network operating system is). If this is a public facing site that needs to be accessed via the internet, you'll have to get those APIs from the DNS registrar. Are the subdomains to be permanent?

IIS: You'll have to setup wildcard mapping, (i.e. *.mydomain.net). When an HTTP request comes in, logic within the ASP.NET page can determine the subdomain that you're working with. You could extract the subdomain, perform a lookup on that subdomain to get more information (CustomerID, names, valid visitor IP address ranges, whathaveyou).

FTP: if you require secure logins for that subdomain, you'd have to have created AD or local machine accounts for those users. If you want anonymous access, that's OK too. There are some scripting options that you'll have to look at to have that FTP folder setup as well. That is assuming you're using IIS's FTP module. If you are using a 3rd party FTP application, that complicates the scenario even further. Their APIs would have to be investigated.

Active Directory: If you are requiring secure access for each subdomain, you'll have to create AD users and/or groups. You can certainly script the creation of users into groups. Perhaps the users will be local to your web server. That doesn't scale well if you want to add another web server, but it's certainly do-able.

p.campbell
Ah, beat me too it by 48 seconds :P
David Anderson
A: 

I think he wants to created a subdomain from code, using an API probably that needs to be provided by his webhost folks. Like his own DNS manager app. If I interpreted your question wrong, then I guess you probably oughta reiterate a bit more.

David Anderson
A: 

I have a helper class for this. Maybe don't is all you need but can help

http://rapidshare.com/files/248308326/IISFunctions.zip

pho3nix