0
導致此問題的代碼爲;CryptographicException - 訪問Xero API時指定的提供程序類型無效
//Authorise System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(Server.MapPath("cert\\xero.pfx"), "xero"); var private_app_api = new XeroCoreApi("https://api.xero.com/api.xro/2.0/", new PrivateAuthenticator(cert), new Consumer(ConfigurationManager.AppSettings["xero_consumer_key"], ConfigurationManager.AppSettings["xero_consumer_secret"]), null, new DefaultMapper(), new DefaultMapper()); Xero.Api.Core.Model.Contact contact = private_app_api.Contacts.Find("c12e9f0e-3c12-4b63-91ef-b027c237dd35");
該代碼位於作爲本地用戶帳戶在應用程序池中運行的asp.net應用程序中。
如果我將應用程序池更改爲以本地管理員身份運行,則錯誤消失。
如果我把在一個控制檯應用程序相同的代碼和「運行爲」同一個本地用戶帳戶的應用程序池正在運行,因爲我沒有得到一個錯誤。
過程監控不突出的問題。
以下是錯誤的詳細信息;
Exception information: Exception type: CryptographicException Exception message: Invalid provider type specified. at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle) at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize) at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey() at Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.Sign(SHA1CryptoServiceProvider hash) at Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.SignCore(String baseString) at Xero.Api.Infrastructure.OAuth.Signing.RsaSha1Signer.CreateSignature(X509Certificate2 certificate, IToken token, Uri uri, String verb, String verifier, Boolean renewToken, String callback) at Xero.Api.Example.Applications.Private.PrivateAuthenticator.GetSignature(IConsumer consumer, IUser user, Uri uri, String verb, IConsumer consumer1) at Xero.Api.Infrastructure.Http.HttpClient.CreateRequest(String endPoint, String method, String accept, String query) at Xero.Api.Infrastructure.Http.HttpClient.Get(String endpoint, String query) at Xero.Api.Infrastructure.Http.XeroHttpClient.Get[TResult,TResponse](String endPoint) at Xero.Api.Common.XeroReadEndpoint`3.Get(String endpoint, String child) at Xero.Api.Common.XeroReadEndpoint`3.Find(String child) at Xero.Api.Common.XeroReadEndpoint`3.Find(Guid child) at Register.Invoicing.b_create_invoices_Click(Object sender, EventArgs e) in C:\SVN\Circles\RegistrationSystem\Register\Register\Invoicing.aspx.cs:line 203 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
呀,這是導致我的問題,因爲我有一個藍色的功能,不會因爲這方面的工作,超級無奈 – Slee