使用Azure的API,我如何列出和虚拟目录添加到网站? [英] Using the Azure API, how do I list and add virtual directories to a website?

查看:190
本文介绍了使用Azure的API,我如何列出和虚拟目录添加到网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个虚拟目录从使用Azure的API WinForms应用程序添加到Azure的网站。我可以列举网站在我的web页面,但我不能找到一种方法,让我接触到该网站的虚拟目录。

下面是我的code:

 字符串证书路径= Properties.Settings.Default.AzureCertificatePath;
        字符串certPassword = Properties.Settings.Default.AzureCertificatePassword;
        字符串subscriptionId = Properties.Settings.Default.AzureSubscriptionId;
        VAR证书=新X509Certificate2(证书路径,certPassword,X509KeyStorageFlags.MachineKeySet);        VAR威望=新CertificateCloudCredentials(subscriptionId,证书);        使用(VAR的客户=新WebSiteManagementClient(CRED))
        {
            变种空格= client.WebSpaces.List();
            的foreach(在空间VAR空间)
            {
                Console.WriteLine(空间:{0},space.Name);                VAR网站= client.WebSpaces.ListWebSites(space.Name,新WebSiteListParameters {PropertiesToInclude = {姓名}}); *** //我在哪里可以找到哪些属性可以包含在该数组中?***
                的foreach(在网站VAR网站)
                {
                    *** //善有善报,这里要说明在这个特定网站的虚拟目录*** ??????
                }
            }
        }


解决方案

我发现Azure的Web服务API不提供访问一个Web应用程序的虚拟目录/应用程序,尽管有关的REST的API,它使用一样。

幸运的是,管理API是开源的(我想获得该网站的管理API的v3.0.0.0,匹配什么我NuGet'd,我发现在这里:的 https://github.com/Azure/azure-sdk-for-net/commits/master?页= 79 ),所以有一点毅力和摆弄.targets文件和引用的NuGet,你可以在 WebSiteManagement 项目的源$ C ​​$ C到您的解决方案,而不是被引用的DLL,你可能从下载的NuGet

在这里,如果你去到你的 client.WebSites.GetConfiguration 方法,坚持在一个断点,并捕获HTTP响应回来了 - 你会看到,在JSON在 VirtualApplications 在您的网站确实存在。

从那里,你可以编辑你的源$ C ​​$ C副本公开这些对象结构的,几乎相同的方式,其他对象结构映射出了JSON(的如的HandlerMappings )。

同样地更新它们,你需要在VirtualApplications(在ewact相同的格式)添加到 Microsoft.WindowsAzure.Management.WebSites.Models.WebSiteUpdateConfigurationParameters ,并通那到 client.WebSites.UpdateConfiguration (你还需要修改映射你的VirtualApplications对象结构回JSON格式相同)。

伟大的作品对我做这种方式。

注意/免责声明: GitHub的网站文件没有提到太多源$ C ​​$ C被自动生成,而你不应该真正去编辑该code,而不是引发问题就得到它排序的项目。我没有足够的时间来做到这一点,需要得到它与本地的code拷贝工作的直接方式而已,所以我的解决方案确实,因为你会当你看着一个来源注意到,涉及添加该自动gen之类code。它的伟大工程,但我要在你凭良心点项目业主的警告有关与自动gen之类code修修补补。

I am trying to add a Virtual Directory to an Azure Web Site from a WinForms Application using the Azure API. I can enumerate the WebSites on in my webspace, but I cannot find a method that allows me access to the Virtual Directories in the WebSite.

Here is my code:

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

解决方案

I found that the Azure web services API does not offer access to the virtual directories/applications on a web app, although the underlying REST API's that it uses does.

Luckily, the management API is open source (I wanted to get the v3.0.0.0 of the website management API, matching what I had NuGet'd, which I found here: https://github.com/Azure/azure-sdk-for-net/commits/master?page=79) so with a little perseverance and messing about with .targets files and NuGet references, you can get the source code of the WebSiteManagement project into your solution instead of the referenced DLL that you likely downloaded from NuGet.

From there, if you go into your client.WebSites.GetConfiguration method, stick a breakpoint in and capture the HTTP response returned - you'll see that in the JSON the VirtualApplications on your website are indeed there.

From there, you can edit your copy of the source code to expose those object structures out, much the same way that other object structures are mapped out of the JSON (e.g. HandlerMappings).

Likewise for updating them, you need to add the VirtualApplications (in the ewact same format) into the Microsoft.WindowsAzure.Management.WebSites.Models.WebSiteUpdateConfigurationParameters, and pass that into client.WebSites.UpdateConfiguration (which you will also need to amend to map your VirtualApplications object structure back into JSON in the same format).

Works great for me doing it this way.

Note/Disclaimer: The GitHub site documentation does mention that much of the source code was autogenerated, and that you shouldn't really go editing that code, instead raise an issue on the project about getting it sorted. I didn't have the time to do this and needed an immediate way of getting it working with my local copy of the code only, so my solution does, as you'll note when you look a the source, involve adding to that auto-gen'd code. It works great, but I should in good conscience point you to the project owner's warnings about tinkering with the auto-gen'd code.

这篇关于使用Azure的API,我如何列出和虚拟目录添加到网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆