我有一個Azure網站和一個Azure Blob,我正用它來存儲.cer X509證書文件。從Azure Blob保存X509證書並在Azure網站中使用它
目標是從blob獲取.cer文件並使用它執行操作(該代碼位於我的Azure網站的Controller
中,並且工作正常)。
當我在本地運行的代碼(不發表我的網站),它的作品,因爲我將它保存在D:\
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("myContainer");
// Retrieve reference to a blob named "testcert.cer".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("testcert.cer");
// Save blob contents to a file.
using (var fileStream = System.IO.File.OpenWrite("D:/testcert.cer"))
{
blockBlob.DownloadToStream(fileStream);
}
**string certLocation = "D:/testcert.cer";
X509Certificate2 myCert = new X509Certificate2();
myCert.Import(certLocation);**
我無法弄清楚如何/在那裏我可以保存它。如果我嘗試使用Import方法,但輸入一個url(存儲證書的Azure blob的url),我得到一個錯誤,因爲Import無法處理url。
任何想法,我可以用作在Azure網站或blob的臨時存儲,並從它創建一個X509Certificate
?
編輯:我想添加更多關於我試圖解決的問題的細節。
從Azure blob獲取證書文件並將其寫入Azure網站。
使用
X509Certificate
對象創建將被用來在我寫在我的控制器的方法的調用證書上.IMPORT(string pathToCert
)。
我已經能夠通過手動添加.cer
文件通過FTP我的網站的wwwroot文件夾來解決1。但現在當我使用Server.MapPath("~/testcert.cer");
來獲取路徑獲取我的證書我得到這個:D:\home\site\wwwroot\testcert.cer
顯然,當導入方法使用上面,因爲一旦它部署到我的蔚藍網站的路徑字符串,它不是一個有效的路徑,因此我證書創建失敗。
任何想法?謝謝!
關注此空間:在Azure的網站進行交接證書更好地支持即將推出:) – 2014-09-08 18:26:28