【问题标题】:Using the Azure API, how do I list and add virtual directories to a website?使用 Azure API,我如何列出虚拟目录并将其添加到网站?
【发布时间】:2015-03-12 00:58:55
【问题描述】:

我正在尝试使用 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??????***
                }
            }
        }

【问题讨论】:

  • 对于那些晚于 OP 的人来说更多:PropertiesToInclude 导致库将 propertiesToInclude 添加到 API URL 中的 queryString 中,并且该查询字符串 什么都不做 -一点也不。截至 2016 年 4 月,.NET 库仍然严重过时,不应使用。

标签: c# winforms azure


【解决方案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(以 ewact 相同的格式)添加到 Microsoft.WindowsAzure.Management.WebSites.Models.WebSiteUpdateConfigurationParameters,并将其传递给 client.WebSites.UpdateConfiguration(您还需要修改它以将您的 VirtualApplications 对象结构映射回JSON 格式相同)。

这样做非常适合我。

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

【讨论】:

    猜你喜欢
    • 2015-02-04
    • 2013-02-13
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多