【问题标题】:How can I let my customers have their own domains redirect to my server and identify them? [closed]如何让我的客户将自己的域重定向到我的服务器并识别他们? [关闭]
【发布时间】:2012-07-17 12:24:28
【问题描述】:

我有一个问题我找不到答案,因为我不知道如何用英文搜索它:)

如何让我的客户将他们自己的域重定向到我的服务器并识别他们?就像WordPress。

例如,我创建了一个简单的 CMS 系统,客户可以注册并拥有自己的页面,例如 john.mysite.com。但如果他们想使用他们的域,我是否必须在 Plesk 上创建所有这些域?顺便说一句,我在 Plesk 中使用 IIS 7.5。

我也不想使用 iframe。

示例;

john.mywebsite.com/categories-150.html --> www.johnswebsite.com/categories-150.html

但它应该使用相同的代码。我不应该为此复制所有源代码并创建单独的域。

当然,我可以让他们将他们的 ns 更改为我的服务器并指定一个 A 记录,但我如何通过代码识别它? (C# ASP.NET MVC)我假设我可以通过数据库搜索域名并获取 ID,但是如何传递域名?

希望你能理解:)

感谢和问候

【问题讨论】:

    标签: c# asp.net-mvc dns iis-7.5 nameservers


    【解决方案1】:

    你的问题我不清楚,但我会尽力帮助你

    首先您需要更改 DNS 设置并指向您的 IP

    然后在 iis 中创建一个站点并将该域添加为主机头

    要获取请求的 url,你可以使用

    Request.Url or look in the Request.ServerVariables["SERVER_NAME"]
    

    有关服务器变量的更多信息 http://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx

    【讨论】:

    • Hostheader 看起来不错,让我试试。
    【解决方案2】:

    在我看来,这是一些字符串操作并使用字典来获取您想要的内容。

    例如:

    // preparation of the dictionary to map your sub domain to the clients website
    IDictionary<String, String> clientRedirect = new Dictionary<String, String>();
    clientRedirect.Add("john", "www.johnswebsite.com");
    
    ...
    
    // actual processing incoming request
    String strToRedirect = @"john.mywebsite.com/categories-150.html";
    String relPath = strToRedirect.Substring(strToRedirect.IndexOf(@"/")); // = "/categories-150.html"
    String subdomain = strToRedirect.Substring(0, strToRedirect.IndexOf(@"/"));
    subdomain = subdomain.Replace(@".mywebsite.com", ""); // = "john"
    
    String newUrl = clientRedirect[subdomain] + relPath; // = "www.johnswebsite.com/categories-150.html"
    
    WebRequest request = WebRequest.Create(newURL); // use the URL
    

    或者你的意思是不同的?

    【讨论】:

      猜你喜欢
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2010-12-06
      相关资源
      最近更新 更多