![](/img/trans.png)
[英]502 error when generating X509Certificate2 from p12 certificate in Azure Websites for Google API
[英]How to manage Google Analytics certificate safely on Azure websites
我閱讀了有關如何在C#中使用Google Analytics(分析)的教程 。
我想在我的ASP.NET5應用程序中使用它,並且我想正確地使用它。 我需要使用服務帳戶身份驗證(我的應用程序將獲取由我生成的統計信息和預設報告給用戶)。
Google以兩種形式提供證書
我當時正在考慮從JSON證書中提取值並將其設置為配置,但是我必須實例化X509Certificate2
,該方法僅采用P12文件的路徑,或構造函數中一些神秘的byte[] rawData
。
var certificate = new X509Certificate2(pathToP12File, "myPassword", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) {
Scopes = scopes}.FromCertificate(certificate));
有什么想法怎么辦?
對於WebApp,請轉到Azure門戶 :
使用類似於下面的代碼來檢索證書(注意-在StoreLocation.CurrentUser
,證書存儲在StoreLocation.CurrentUser
:
var thumb = "your-certificate-thumbprint"; var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); var cert = store.Certificates.Cast<X509Certificate2>().FirstOrDefault(xc => xc.Thumbprint == thumb); if (cert == null) { throw new Exception(string.Format("Could not find a certificate with thumbprint {0} in StoreName.{1} at StoreLocation.{2}", thumb, store.Name, store.Location)); }
Web /工作者角色類似,通過門戶(1)將證書上傳到Cloud Service,然后跳過(2)。 對於(3),請注意Web / Worker角色中的證書存儲在StoreLocation.LocalMachine
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.