duandangqin0559 2016-06-05 15:51
浏览 87

通过代码将多个域添加到一个Web应用程序

I have a PHP App running on my Azure. I want my customers to be able to use my application on their own domains. Is it possible to add multiple domains to one single web application? Is there an API or something to add domains to a web app programatically?

I have a web.config file that looks like below but it doesn't redirect.

<?xml version="1.0"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite domain requests" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)?([.a-zA-Z0-9]+)$" />
  </conditions>
  <action type="Rewrite" url="http://www.cemiltokatli.com/url={R:1}" appendQueryString="true" />
</rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
  • 写回答

2条回答 默认 最新

  • dongshou2024 2016-06-05 17:10
    关注

    For that, you need to move your web app to the shared/standard mode and:

    1) configure url rewriting (like described here)

    2) configure multiple domain names using Site.HostNames property. That property can be used for setting additional domains. Unfortunately, i have no PHP code snippet, but working C# code is below (implemented using SDK). And, again, unfortunately, but it looks like the official Azure PHP SDK does not provide the same functionality. The way here would be to write a REST API wrapper using, for example, the snippet below as a reference. If there is no possibility from your side to execute the code and catch the request, i can do that a little later, if that will help.

    public const string base64EncodedCertificate = "ManagementCertificateValueFromPublishSettingsFile";
    public const string subscriptionId = "AzureSubscriptionId";
    
    static SubscriptionCloudCredentials getCredentials()
    {
        return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
    }
    static void Main(string[] args)
    {
        WebSiteManagementClient client = new WebSiteManagementClient(getCredentials());
    
        WebSpacesListResponse n = client.WebSpaces.List();
        n.Select(p =>
        {
            Console.WriteLine("webspace {0}", p.Name);
            WebSpacesListWebSitesResponse websitesInWebspace = client.WebSpaces.ListWebSites(p.Name,
                  new WebSiteListParameters()
                  {
                  });
            websitesInWebspace.Select(o =>
            {
                Console.Write(o.Name);     
    
                return o;
            }).ToArray();
            return p;
        }).ToArray();
    
        Console.ReadLine();
        var configuration = client.WebSites.Get("WebSpaceName", "WebSiteName", new WebSiteGetParameters());
    
        configuration.WebSite.HostNames.Add("new domain");
        var resp = client.WebSites.Update("WebSpaceName", "WebSiteName", new WebSiteUpdateParameters() { HostNames = configuration.WebSite.HostNames });
        Console.WriteLine(resp.StatusCode);
        Console.ReadLine();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效