views:

124

answers:

4

I'm building a site where businesses will be able to sign-up for there own account which should be located at http://businessname.domain.com with the "businessname" changing each time.

I want to do this on a windows server (IIS 7) but am not sure how a go about it.

+4  A: 

via http://forums.asp.net/t/874598.aspx

If your DNS provider (ie. ISP) have "wildcard" option you could set *.mydomain.com -> myIP

Next step. Option #1 Make a script that creates 1 sites for each subdomain in IIS Option #2 Make a url_rewrite script that rewrites urls to correct folder on-the-fly.

option 2 is probably what you are looking for (and is STRONGLY recommended and preferred to option 1).

more info about url rewriting on iis7: http://learn.iis.net/page.aspx/460/using-url-rewrite-module/

The Microsoft URL Rewrite Module for IIS 7.0 provides flexible rules-based rewrite engine >that can be used to perform broad spectrum of URL manipulation tasks, including, but not >limited to:

  • Enabling user friendly and search engine friendly URL with dynamic web applications;
  • Rewriting URL’s based on HTTP headers and server variables;
  • Web site content handling;
  • Controlling access to web site content based on URL segments or request metadata.

the url rewriting option makes it easy to have hundreds of thousands of companies, their names can be read from the database and a url rewrite will handle the redirects. after that you can forget about it (for the most part) as it will keep on working for all the companies signing up in the future as well.

b0x0rz
+1  A: 

First, you have to configure your DNS server to resolve *.domain.com to the IP of your server.

Then, you have two choices:

  • Every time a new account is created, you add its host to the configuration of IIS, so it is bound to a directory. I'm not sure how to do this programmatically.
  • Every time a request is made to the server, you check the host, and redirect the client to the site corresponding to the host. It can either be an explicit redirect (the client arrives on http://businessname.domain.com/ and is redirected to http://sites.domain.com/businessname/ ) or implicit (the client arrives on http://businessname.domain.com/ and internally, the application located on a directory dedicated to businessname and treats the request.
FWH
A: 

This involves :

  • Wildcard DNS Mapping
  • Using the IIS API to add hostnames to a domain e.g. businessname.domain.com
  • Programatic impersonation (as the code needs a higher priveledge to use the IIS API than just NETWORK SERVICE

Once you programatically add the host name the wildcard mapping enables it to be resolved.

The URL Rewrite option would be cleaner, but with the physical domain, you could offer FTP Access and other things as it would be a full domain.

Andrew

REA_ANDREW
+1  A: 

Generally, the better approach to this (if possible) is to not use Host Headers or separate IIS sites for each signup. Simply dedicate an IP address to that application that responds to all requests on Port 80 (or whatever port you use) and let your application detect the host header on request. This way, if you have 1,000 signups you don't end up with 1,000 "things" that need to be configured properly at the OS/services layer.

Alternatively if you just want the code, not sure what language you're looking at, but see below for C#...

http://forums.iis.net/t/1151463.aspx

routeNpingme