2
我正在寻找一种方法来使用C#从部署的Windows Azure云服务中读取设置。是否有任何Azure SDK可以轻松加载此值?从Azure的门户网站使用.NET C从azure云服务读取配置设置#
截图显示我想读一下设置:
[EDIT1]
我错过了补充一点,我试图从外部应用程序加载的设置,而不是从它自己的服务。
我正在寻找一种方法来使用C#从部署的Windows Azure云服务中读取设置。是否有任何Azure SDK可以轻松加载此值?从Azure的门户网站使用.NET C从azure云服务读取配置设置#
截图显示我想读一下设置:
[EDIT1]
我错过了补充一点,我试图从外部应用程序加载的设置,而不是从它自己的服务。
根据你的描述,我认为你可以利用Microsoft Azure Management Libraries检索配置设置,你可以按照下面的步骤:
导出证书的.CER文件并上传到您的天蓝色订阅,更多详情,你可以关注这个tutorial
我创建了一个控制台应用程序,并引用微软Azure管理库,这里是核心代码:
private static X509Certificate2 GetStoreCertificate(string thumbprint)
{
List<StoreLocation> locations = new List<StoreLocation>
{
StoreLocation.CurrentUser,
StoreLocation.LocalMachine
};
foreach (var location in locations)
{
X509Store store = new X509Store("My", location);
try
{
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection certificates = store.Certificates.Find(
X509FindType.FindByThumbprint, thumbprint, false);
if (certificates.Count == 1)
{
return certificates[0];
}
}
finally
{
store.Close();
}
}
throw new ArgumentException(string.Format(
"A Certificate with Thumbprint '{0}' could not be located.",
thumbprint));
}
static void Main(string[] args)
{
CertificateCloudCredentials credential = new CertificateCloudCredentials("{subscriptionId}", GetStoreCertificate("{thumbprint}"));
using (var computeClient = new ComputeManagementClient(credential))
{
var result = computeClient.HostedServices.GetDetailed("{your-cloudservice-name}");
var productionDeployment=result.Deployments.Where(d => d.DeploymentSlot == DeploymentSlot.Production).FirstOrDefault();
}
Console.WriteLine("press any key to exit...");
Console.ReadKey();
}
你可以从productionDeployment.Configuration
检索配置设置如下:
鉴于编辑,我已经删除了我的答案。我不确定你如何做到这一点 - 对不起。 – john
布鲁斯回答说技术上可行,但你为什么要这么做?似乎是一个不正确的方法来分享配置.. – yonisha