X509证书"System.Security.Cryptography.CryptographicException"访问被拒绝. [英] X509 Certificate "System.Security.Cryptography.CryptographicException" Access is denied.

查看:78
本文介绍了X509证书"System.Security.Cryptography.CryptographicException"访问被拒绝.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用Google Analytics(分析)客户端库来获取一些数据并将其显示在CMS面板上.我已经在分析中获得了服务帐户和所有授予的权限,但是出现以下错误:

I am using Google Analytics Client Library to fetch some data and display it on my CMS Panel. I've got my service account and all the permissions granted to it in my analytics, but I am getting this following error:

{消息":访问被拒绝.","StackTrace":".在System.Security.Cryptography.X509Certificates.X509Store.Add(X509Certificate2证书)处\ r \ n在Thunder.Main.Default.Authenticate()\ r \ n处在Thunder.Main.Default.GetChartData()," ExceptionType";:"System.Security.Cryptography.CryptographicException"}

{"Message":"Access is denied.\r\n","StackTrace":" at System.Security.Cryptography.X509Certificates.X509Store.Add(X509Certificate2 certificate)\r\n at Thunder.Main.Default.Authenticate()\r\n at Thunder.Main.Default.GetChartData()","ExceptionType":"System.Security.Cryptography.CryptographicException"}

我正在使用共享的托管服务器,因此无法访问IIS.我与托管服务器联系,以更改应用程序池标识并将负载用户配置文件设置为true,但是他们不允许我这样做.这是我的验证码:

I am using a shared hosting server, so I have no access to IIS. I contacted with my hosting to change application pool identity and setting load user profile to true, but they didn't allow me to do it. This is my authentication code:

 public static AnalyticsService Authenticate()
    { 
        string[] scopes = new string[] { AnalyticsService.Scope.Analytics,                 
     AnalyticsService.Scope.AnalyticsManageUsers};    

        string keyFilePath = @"G:\PleskVhosts\mydomainname\httpdocs\App_Data\API Project-2f74017ed363.p12";    // found in developer console
        string serviceAccountEmail = "myconsoleapiaccount@developer.gserviceaccount.com";  // found in developer console

        var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
        ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail) { Scopes = scopes }.FromCertificate(certificate));

        AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "myappname",
        });
}

我已经为此工作了两个星期,但我没有运气.我愿意接受任何建议,非常感谢.

I've been working on this for 2 weeks, and I had no luck. I am open to any suggestions, thank you so much in advance.

推荐答案

你好,

根据错误,很可能您正在使用的证书无效,您可以尝试从提供者那里获取正确的证书.

According to the error, most probably the certificate you're using is not valid, you could try to get the correct certificate from the provider.

顺便说一句,该论坛仅适用于Microsoft产品.但是您的问题是关于"Google Analytics(分析)客户端库"的;这超出了我们的范围.建议您向Google支持团队寻求帮助,或在其论坛中发布您的问题.

By the way, this forum is only for Microsoft products. But your question is about the "Google Analytics Client Library" which is out of our scope. I recommend you ask Google support team for help, or post your question in their forum.

非常感谢!


这篇关于X509证书"System.Security.Cryptography.CryptographicException"访问被拒绝.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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