【发布时间】:2016-10-07 07:02:13
【问题描述】:
我们有一个使用 .Net Framework 4.0 和 IIS 7 的网站。 在 Paypal 的最后一次更新之后,我们的 IPN 处理程序不再工作。我们有这个错误: The request was aborted: Could not create SSL/TLS secure channel sandbox account 因此,当我们使用 .Net Framework 4.0 时,我们添加了下一行:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
现在我们有另一个错误: 底层连接已关闭:发送时发生意外错误。
处理响应的类基于以下示例: https://mvcsamples.svn.codeplex.com/svn/trunk/Kona.Web/Controllers/PayPalController.cs
添加前一行后,现在看起来像这样:
private string GetPayPalResponse(Dictionary<string, string> formVals, bool useSandbox)
{
string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
: "https://www.paypal.com/cgi-bin/webscr";
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);
// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
StringBuilder sb = new StringBuilder();
sb.Append(strRequest);
foreach (string key in formVals.Keys)
{
sb.AppendFormat("&{0}={1}", key, formVals[key]);
}
strRequest += sb.ToString();
req.ContentLength = strRequest.Length;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://urlort#");
//req.Proxy = proxy;
//Send the request to PayPal and get the response
string response = "";
using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
{
streamOut.Write(strRequest);
streamOut.Close(); linea = 10;
using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
{
response = streamIn.ReadToEnd();
}
}
return response;
}
在这一行引发了异常:
using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
我们不确定是否可以让 Paypal 与 .NET Framework 4.0 一起使用。据说可以使用我们添加的行。但不工作。也许代码或 IS 7 中需要进行更多更改。但我们找不到示例。
感谢您的帮助。
编辑:
我差点忘了提到该项目是使用 Visual Studio 2010 开发的。没有 .NET Framework 4.5。
编辑 2:
我调查了这个问题,发现我们的服务器 Windows Server 2008 不支持 TLS 1.2(查看表格): https://blogs.msdn.microsoft.com/kaushal/2011/10/02/support-for-ssltls-protocols-on-windows/ 但在那之后,我发现了 2016 年所有版本的 SQL Server 的新更新。 https://blogs.msdn.microsoft.com/sqlreleaseservices/tls-1-2-support-for-sql-server-2008-2008-r2-2012-and-2014/ http://blogs.sqlsentry.com/aaronbertrand/tls-1-2-support-read-first/
但最后我的老板由于某些原因决定不使用新更新或使用注册方法更新服务器。
所以我无法证明任何解决问题的方法。给您添麻烦了。
【问题讨论】:
-
根据此页面link TLS 1.2 和 TLS 1.1 在 Framework 4.0 中不受支持
-
您找到解决此问题的方法了吗?我们使用 .NET 4.6.1,因此指定 Tls | 没有问题。 tls11 | ServicePointManager.SecurityProtocol 的 Tls12。在设置 Tls12 后,我正在为第二个异常“底层连接已关闭”而苦苦挣扎。日子白白浪费了。无论我尝试什么,我都会得到这个异常。显然还有其他需要设置或配置的东西,但是什么?
标签: c# asp.net-mvc visual-studio-2010 paypal-ipn paypal-sandbox