PayPal – ASP.NET中等信任

最近,我们的虚拟主机提供商转移到所有共享的ASP.NET网站托pipe的中等信任级别。 因此,我们通过PayPal的SOAP API完成交易有一些问题。 具体而言,使用以下堆栈跟踪引发SecurityExceptionexception:

[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0 System.Security.CodeAccessPermission.Demand() +58 System.Net.ServicePointManager.set_CertificatePolicy(ICertificatePolicy value) +54 com.paypal.sdk.core.APICallerBase.SetTrustManager() +30 com.paypal.sdk.core.soap.SOAPAPICaller..ctor() +14 com.paypal.sdk.services.CallerServices..ctor() +23 ... 

我跟踪了PayPal SOAP SDK中的违规方法的来源。

 /// <summary> /// To Accept all un-trusted certificate /// </summary> private void SetTrustManager() { //This code is added to accept all un-trusted certificate ie self-signed certificate if (Config.Instance.TrustAll) { //ServicePointManager.CertificatePolicy = TrustAllCertificatePolicy.Instance; ServicePointManager.CertificatePolicy = new MyPolicy(); } } // SetTrustManager 

是否知道需要对我们的项目和/或服务器进行哪些更改以使SDK能够在中等信任环境中运行? 是否有必要接受所有不可信任的证书?

恐怕不支持,你需要使用经典的HTTPS接口集成。 否则,如果您想以任何方式使用SDK,则必须在服务器上启用完全信任模式。