Creating Subdomains Programmatically

家住魔仙堡 提交于 2019-12-03 08:45:53

问题


I am looking for a solution to create subdomains programmatically in ASP.NET, ASP.NET MVC and PHP. Specifically, a user profile page should resolve for both: www.domain.com/profilename or http://profilename.domain.com .


回答1:


Update your DNS settings of the particular domain so that *.domain.com all point to the same host.

Then, programmatically check and see if the first part of the URL used contains the subdomain you are looking for, and act accordingly. For example, if the first part contains a given profilename, then retrieve that particular profiles collection of data from your DB and display it to the user.

Make sure your web application uses relative links, so that if the user arrives at the site using a subdomain, that you don't redirect them elsewhere.




回答2:


There is no generic way to create subdomains. You will need to call an API provided by your ISP or DNS provider -- typically SOAP or REST.

Either that, or use a wildcard domain (*).

On the IIS side, be sure to configure you application so that it doesn't use Host headers.




回答3:


You could try:

AppDomain subDomain = AppDomain.CreateDomain("ProfileUserDomain");

Although you may have to configure your DNS to allow request from your code. Dynamic DNS services could be your answer.



来源:https://stackoverflow.com/questions/1943356/creating-subdomains-programmatically

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