1

造成这种情况的代码是;

            //授权
            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/",
                新的 PrivateAuthenticator(证书),
                新消费者(ConfigurationManager.AppSettings["xero_consumer_key"],ConfigurationManager.AppSettings["xero_consumer_secret"]),
                无效的,
                新的 DefaultMapper(),
                新的 DefaultMapper());
                Xero.Api.Core.Model.Contact 联系人 = private_app_api.Contacts.Find("c12e9f0e-3c12-4b63-91ef-b027c237dd35");

该代码位于作为本地用户帐户在应用程序池上运行的 asp.net 应用程序中。

  • 如果我将应用程序池更改为以本地管理员身份运行,错误就会消失。

  • 如果我将相同的代码放在控制台应用程序中并以相同的本地用户帐户“运行”,则应用程序池正在运行,因为我没有收到错误。

  • 进程监视器不会突出显示任何问题。

以下是错误详情;

异常信息:
    异常类型:CryptographicException
    异常消息:指定的提供程序类型无效。

   在 System.Security.Cryptography.Utils.CreateProvHandle(CspParameters 参数,布尔随机密钥容器)
   在 System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType,CspParameters 参数,布尔 randomKeyContainer,Int32 dwKeySize,SafeProvHandle&safeProvHandle,SafeKeyHandle&safeKeyHandle)
   在 System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
   在 System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize,CspParameters 参数,布尔值 useDefaultKeySize)
   在 System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
   在 Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.Sign(SHA1CryptoServiceProvider 哈希)
   在 Xero.Api.Infrastructure.ThirdParty.Dust.RsaSha1.SignCore(字符串 baseString)
   在 Xero.Api.Infrastructure.OAuth.Signing.RsaSha1Signer.CreateSignature(X509Certificate2 证书,IToken 令牌,Uri uri,字符串动词,字符串验证器,布尔 renewToken,字符串回调)
   在 Xero.Api.Example.Applications.Private.PrivateAuthenticator.GetSignature(IConsumer 消费者,IUser 用户,Uri uri,字符串动词,IConsumer 消费者 1)
   在 Xero.Api.Infrastructure.Http.HttpClient.CreateRequest(字符串端点,字符串方法,字符串接受,字符串查询)
   在 Xero.Api.Infrastructure.Http.HttpClient.Get(字符串端点,字符串查询)
   在 Xero.Api.Infrastructure.Http.XeroHttpClient.Get[TResult,TResponse](字符串端点)
   在 Xero.Api.Common.XeroReadEndpoint`3.Get(字符串端点,字符串子)
   在 Xero.Api.Common.XeroReadEndpoint`3.Find(String child)
   在 Xero.Api.Common.XeroReadEndpoint`3.Find(Guid child)
   在 C:\SVN\Circles\RegistrationSystem\Register\Register\Invoicing.aspx.cs:line 203 中的 Register.Invoicing.b_create_invoices_Click(Object sender, EventArgs e)
   在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   在 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)
   在 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)
4

1 回答 1

1

当我在应用程序池上将“启用 32 位应用程序”设置为 true 时,该错误消失了。我发现它为什么在设置为 false 但以具有管理权限的用户身份运行应用程序池时起作用?

我希望能更好地解释发生了什么。

于 2017-09-23T21:57:39.130 回答