ASP.NET - how to create subdomain in asp.net by code

Asked By Reena Jain on 30-Jan-10 03:27 PM
Hi,

For eg I am creating one site , and in site if some one registered himself , then a subdomain should generate with his name and country like if user name is abc and country is india . so it should be www.abc.india.xyz.com.
How its possible to do it by code.

thanks in advance

Robbe Morris replied to Reena Jain on 30-Jan-10 06:25 PM

You still need a DNS entry on the primary DNS server that manages your domain.  Are you managing your own DNS server?  If not, you have to make arrangements for someone to add the entries for you.

Then, you can add the host header entries in IIS fairly easily.  Some of the code you'll need is in this article.

http://www.eggheadcafe.com/tutorials/aspnet/d4bba585-b517-4834-8476-ff05b085d86e/iis--create-app-pools-v.aspx

mv ark replied to Reena Jain on 30-Jan-10 09:16 PM
An alternative to implementing subdomain prefixes by configuring them on the DNS servers 
hosting your domain name is to create fake subdomain addresses with URLrewriting.

URLRewriting at the IIS level can be done using ISAPI filters. Check out these 2 -

URL Replacer - http://www.motobit.com/help/url-replacer-rewriter/iis-mod-rewrite.asp

ISAPI_Rewrite Lite is a free & powerful URL manipulation engine based on regular expressions to alter or obfuscate URLs. Check - http://www.isapirewrite.com/

Also check this thread - http://eggheadcafe.com/community/aspnet/2/82142/url-rewriting.aspx