creating sub-domains on signup

左心房为你撑大大i 提交于 2019-12-22 06:46:13

问题


I'm building a site where businesses will be able to sign-up for there own account which should be located at http://businessname.example.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.


回答1:


First, you have to configure your DNS server to resolve *.example.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.example.com/businessname/ ) or implicit (the client arrives on http://businessname.example.com/ and internally, the application located on a directory dedicated to businessname and treats the request.



回答2:


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.




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/1159050/creating-sub-domains-on-signup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!