Connecting Tech Pros Worldwide Help | Site Map

Programmatically create subdomains (host header records)

Newbie
 
Join Date: Mar 2009
Posts: 5
#1: Sep 29 '09
I implemented a URL rewriter which worked reasonably well, but now I am creating other sites on the same server (single IP). Because IIS will not accept subdomain wildcards (*.subdomain.com), it resolves the subdomain traffic back to the default site (e.g. the site with empty host header). From there it is possible to rewrite and pass the traffic back to correct web app and use the referring agent to get original url, but this gets messy in practice.

So I am looking for way to programmatically create/remove the host header records for the subdomains. Is there any programmatic interface to IIS, or some file to plug the header values directly?

Thanks,
Lauren
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Sep 29 '09

re: Programmatically create subdomains (host header records)


What version of IIS are you using?

-Frinny
Newbie
 
Join Date: Mar 2009
Posts: 5
#3: Sep 29 '09

re: Programmatically create subdomains (host header records)


Using IIS v6

Thanks in advance for your help,
Lauren
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#4: Sep 29 '09

re: Programmatically create subdomains (host header records)


I'm not sure if this is going to help you but...this article on URL Rewriting in ASP.NET has a lot of information on the topic....

-Frinny
Newbie
 
Join Date: Mar 2009
Posts: 5
#5: Sep 29 '09

re: Programmatically create subdomains (host header records)


Yes i had looked at that when setting up the URL rewriting. Unfortunately it does not address rewriting URL for subdomains of site other than default.
codegecko's Avatar
Moderator
 
Join Date: May 2007
Location: United Kingdom
Posts: 395
#6: Sep 30 '09

re: Programmatically create subdomains (host header records)


Hi lmeyers,

If you're creating subdomains on a single IP, can you explain why you need a wildcard on subdomains - do you plan on running one site on all subdomains on your site?

URL rewriting will be tricky to say the least, and until you can explain the background a little more, my recommendation is normally this: either just to use multiple sites, one IP, one host header on each for each subdomain if you plan on running single sites - or use one site, one IP, no host header so it catches all incoming traffic.

If you then want to do rewriting with the second option you have choices:
1) If your single site is running ASP.NET then you could write a URL rewriter as Frinny's link pointed to. I've had great success in this area, especially as ASP.NET now supports Regex and you can link it directly to database lookups too - especially useful for content management systems and advanced URL rewriting.
2) If you run multiple sites, single host header each, then Ionic ISAPI Rewriter is the tool for you. Supports Regex lookups, header modifications, 301/302s, all in a nice ISAPI that you can dump straight onto the individual website to rewrite its' URLs.
3) If you really want to go down the route of programmatically controlling the host headers on a single site, then check out the WMI IIS reference on MSDN which will give you all the class references and function calls necessary to create objects programmatically and then add/edit/remove host headers as necessary.

Hope this helps.

codegecko
Newbie
 
Join Date: Mar 2009
Posts: 5
#7: Sep 30 '09

re: Programmatically create subdomains (host header records)


Thanks that is helpful info. Situation is that I have multiple sites each of which requires dynamic subdomains. I am using the Intelligencia URL rewriter which worked fine with single site subdomains. I had the rewrite configuration contained within the web.config file and the site was setup with no undefined host header record (e.g. default IIS site). Now with a second site also supporting dynamic subdomains all those requests go back to default site and URL rewriter on second site never even sees the request.

Still do not understand why IIS will not support *.domain.com the way the DNS system does. In any case, I have ordered more IP addresses which I think will resolve this silly issue.

Thanks for your input.
codegecko's Avatar
Moderator
 
Join Date: May 2007
Location: United Kingdom
Posts: 395
#8: Oct 1 '09

re: Programmatically create subdomains (host header records)


Aha, now I see the problem.
Internet Information Services' host header system doesn't recognise widlcards, you are quite right. The best way around this is to use a fresh, dedicated IP with no host header and point all the necessary subdomains to that IP.

codegecko
Reply

Tags
host header, subdomain