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