我需要升级google API OAuth 2(但仍然使用一些旧的GData API),并且几乎只使用这篇文章,它通过iis express在本地工作得很好。
为方便起见,代码为:
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using Autofac;
using D.Core.Intelligence;
using Google.Apis.Auth.OAuth2;
using Google.GData.Analytics;
using Google.GData.Client;
namespace D.Analytics
{
public class AnalyticsModule : Module
{
private const string ServiceAccountEmail = "3504f5u6sqlm@developer.gserviceaccount.com";
private static readonly string KeyPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ?? AppDomain.CurrentDomain.BaseDirectory, "Key.p12");
private static readonly X509Certificate2 Certificate = new X509Certificate2(KeyPath, "notasecret", X509KeyStorageFlags.Exportable);
private readonly ServiceAccountCredential _credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(ServiceAccountEmail)
{
Scopes = new[] { "https://www.googleapis.com/auth/analytics" }
}.FromCertificate(Certificate));
protected override void Load(ContainerBuilder builder)
{
builder.Register(c =>
{
_credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait();
var service = new AnalyticsService("D.com");
var requestFactory = new GDataRequestFactory("razbot2.0");
requestFactory.CustomHeaders.Add(string.Format("Authorization: Bearer {0}", _credential.Token.AccessToken));
service.RequestFactory = requestFactory;
return service;
});
builder.RegisterType<AnalyticsNewsletterTrackingSource>().As<INewsletterTrackingSource>();
builder.RegisterType<AnalyticsSearchTrackingSource>().As<ISearchTrackingSource>();
builder.RegisterType<AnalyticsEmailLinkTracker>().As<IEmailLinkTracker>();
}
}
}
现在这(似乎)在本地工作,但当我上传到我的测试服务器时,我得到w3wp.exe异常,这恐怕我没有经验调试。
我将源代码下载到测试服务器,并试图通过调试点将该进程附加到应用程序,结果得到:
https://i.stack.imgur.com/SzhRy.png我猜它在:
Unhandled exception at 0x000007FD71459F99 (ntdll.dll) in w3wp.exe: 0xC0000374: A heap has been corrupted (parameters: 0x000007FD714AE610).
整个符号加载过程在:http://pastebin.com/Czc8e0cr
内部异常是:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
at D.Analytics.AnalyticsModule..cctor()
与信息:The system cannot find the file specified.
与消息声明相反:文件的路径肯定是准确的,因为我已经通过调试点亲自检查了它。构建操作设置为"content"one_answers"copy if newer",我甚至将。p12证书的值读取到字节数组中,并将其提供给构造函数本身,没有运气!
可能是我在代码中做了一些非常愚蠢的事情,而不是更深入的事情,但它只是让我困惑的是,为什么它没有在局部抛出任何异常!
http://forums.iis.net/p/1226705/2104281.aspx?p=True&t=635720164781539549
如上所述的答案,同样写一个句子,因为SO帖子的主体显然必须至少30个字符。Lorum Ipsum .