Programmatically create subdomains (host header records)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lmeyers
    New Member
    • Mar 2009
    • 5

    Programmatically create subdomains (host header records)

    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.co m), 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 programmaticall y 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
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What version of IIS are you using?

    -Frinny

    Comment

    • lmeyers
      New Member
      • Mar 2009
      • 5

      #3
      Iis 6

      Using IIS v6

      Thanks in advance for your help,
      Lauren

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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

        Comment

        • lmeyers
          New Member
          • Mar 2009
          • 5

          #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.

          Comment

          • JamieHowarth0
            Recognized Expert Contributor
            • May 2007
            • 537

            #6
            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 programmaticall y 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 programmaticall y and then add/edit/remove host headers as necessary.

            Hope this helps.

            codegecko

            Comment

            • lmeyers
              New Member
              • Mar 2009
              • 5

              #7
              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.

              Comment

              • JamieHowarth0
                Recognized Expert Contributor
                • May 2007
                • 537

                #8
                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

                Comment

                Working...