By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,130 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,130 IT Pros & Developers. It's quick & easy.

Programmatically create subdomains (host header records)

P: 5
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
Sep 29 '09 #1
Share this Question
Share on Google+
7 Replies

Frinavale
Expert Mod 5K+
P: 9,731
What version of IIS are you using?

-Frinny
Sep 29 '09 #2

P: 5
Using IIS v6

Thanks in advance for your help,
Lauren
Sep 29 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
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
Sep 29 '09 #4

P: 5
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.
Sep 29 '09 #5

JamieHowarth0
Expert 100+
P: 533
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
Sep 30 '09 #6

P: 5
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.
Sep 30 '09 #7

JamieHowarth0
Expert 100+
P: 533
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
Oct 1 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.