使用Azure API,如何列出虚拟目录并将其添加到网站?

时间:2015-03-12 00:58:55

标签: c# winforms azure

我正在尝试使用Azure API从WinForms应用程序向Azure网站添加虚拟目录。我可以在我的网站空间中枚举网站,但我找不到允许我访问网站中的虚拟目录的方法。

这是我的代码:

        string certPath = Properties.Settings.Default.AzureCertificatePath;
        string certPassword = Properties.Settings.Default.AzureCertificatePassword;
        string subscriptionId = Properties.Settings.Default.AzureSubscriptionId;
        var cert = new X509Certificate2(certPath, certPassword, X509KeyStorageFlags.MachineKeySet);

        var cred = new CertificateCloudCredentials(subscriptionId, cert);

        using (var client = new WebSiteManagementClient(cred))
        {
            var spaces = client.WebSpaces.List();
            foreach (var space in spaces)
            {
                Console.WriteLine("Space: {0}", space.Name);

                var sites = client.WebSpaces.ListWebSites(space.Name, new WebSiteListParameters {PropertiesToInclude = { "Name" } }); ***// Where do I find out what properties can be included in this array?***
                foreach (var site in sites)
                {
                    ***// What goes here to show the virtual directories in this specific website??????***
                }
            }
        }

1 个答案:

答案 0 :(得分:1)

我发现Azure Web服务API不提供对Web应用程序上的虚拟目录/应用程序的访问,尽管它使用的基础REST API也是如此。

幸运的是,管理API是开源的(我想获得网站管理API的v3.0.0.0,与我在NuGet中找到的相匹配,我在这里找到:https://github.com/Azure/azure-sdk-for-net/commits/master?page=79)所以使用.targets文件和NuGet引用几乎没有什么毅力和麻烦,您可以将 WebSiteManagement 项目的源代码添加到您的解决方案中,而不是您可能从NuGet下载的引用DLL。

从那里开始,如果你进入你的client.WebSites.GetConfiguration方法,坚持使用断点并捕获返回的HTTP响应 - 你会发现在JSON中你网站上的VirtualApplications确实存在。

从那里,您可以编辑源代码副本以公开这些对象结构,就像其他对象结构从JSON中映射出来一样(例如HandlerMappings)。

同样,为了更新它们,您需要将VirtualApplications(以相同的格式)添加到Microsoft.WindowsAzure.Management.WebSites.Models.WebSiteUpdateConfigurationParameters中,并将其传递到client.WebSites.UpdateConfiguration(您还需要修改它以映射您的VirtualApplications对象结构以相同的格式返回JSON。)

这样做非常适合我。

注意/免责声明: GitHub站点文档确实提到大部分源代码是自动生成的,并且您不应该真正编辑该代码,而是在项目中引发有关获取的问题它排序了。我没有时间这样做,只需要立即使用我的本地代码副本,所以我的解决方案确实如你所知,当你看到源代码时,涉及添加到该自动-gen'd代码。它工作得很好,但我应该很好地指出项目所有者关于修改自动代码的警告。

相关问题