c# – 使用Azure API,如何列出虚拟目录并将其添加到网站?
我正在尝试使用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是开源的(我想获得v3.0.0.0的网站管理API,匹配我的NuGet’d,我在这里找到了:https://github.com/Azure/azure-sdk-for-net/commits/master?page=79)所以有点坚持不懈和搞乱.目标文件和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代码.它工作得很好,但我应该很好地指出项目业主关于修改自动生成代码的警告. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |