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

标签 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??????***
                }
            }
        }

最佳答案

我发现 Azure Web 服务 API 不提供对 Web 应用程序上的虚拟目录/应用程序的访问,尽管它使用的底层 REST API 提供了访问权限。

幸运的是,管理API是开源的(我想获得网站管理API的v3.0.0.0,与我拥有的NuGet'd相匹配,我在这里找到了它: 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(以 ewact 相同格式)添加到 Microsoft.WindowsAzure.Management.WebSites.Models.WebSiteUpdateConfigurationParameters 中。 ,并将其传递给 client.WebSites.UpdateConfiguration (您还需要修改它以将 VirtualApplications 对象结构映射回相同格式的 JSON)。

这样对我来说效果很好。

注意/免责声明: GitHub 站点文档确实提到大部分源代码是自动生成的,并且您不应该真正去编辑该代码,而是在项目中提出一个关于获取它排序了。我没有时间这样做,并且需要一种直接的方法来让它仅与我的本地代码副本一起工作,所以我的解决方案确实如此,正如您在查看源代码时会注意到的那样,涉及添加到该自动-生成代码。它工作得很好,但出于良心,我应该向您指出项目所有者关于修改自动生成代码的警告。

关于c# - 使用 Azure API,如何列出虚拟目录并将其添加到网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29000178/

相关文章:

c# - 测试 WebApi Controller Url.Link

azure - Microsoft BizTalk Server 与 Azure AppFabric 服务总线...?

c# - ZMQ recv 随机拾取垃圾数据 有谁知道为什么?

c# - 使用 MaxHeight 和 MaxWidth 约束按比例调整图像大小

c# - 使用openXML SDK填充word模板数据

c# - 在 DataGridView 上移动行时的可视标记

c# - 在 PictureBox 上绘制折线

c# - 每像素 Alpha 混合

Azure数据工厂: Response Content is not a valid JObject

azure - 浏览部署在 Azure 中的 Angular 8 应用程序时出错