我正在尝试在我的本地计算机上运行 Visual Studio 2013 网络测试。这是我成功运行的测试(上一次大约 2 个月前)。 Web 测试的第一步是向登录页面发出 GET 请求。它看起来像这样:
获取 https://example.com/Login.aspx
当我在网络浏览器中输入此 URL 时,它成功了。此外,我可以成功地记录一个网络测试,我只需导航到此页面并登录。但是当我尝试重新运行我刚刚记录的网络测试时,我得到了对 GET 请求的响应:
Request failed: An existing connection was forcibly closed by the remote host
IIS 没有在 example.com 上记录任何内容(IIS 不记录 GET 请求)。但是,当我手动登录或记录 Web 测试时,IIS 会正确记录 GET 请求。
example.com 或我的本地主机上的事件查看器中没有记录任何消息。
非常感谢有关如何调试此问题的任何建议。
最佳答案
对我来说,问题是 TLS 握手。通过在 web 测试中添加插件解决。
插件来源:
using System;
using System.ComponentModel;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Microsoft.VisualStudio.TestTools.WebTesting;
[Description("This plugin will force the underlying System.Net ServicePointManager to negotiate downlevel SSLv3 instead of TLS. WARNING: The servers X509 Certificate will be ignored as part of this process, so verify that you are testing the correct system.")]
public class TLSPlugin : WebTestPlugin
{
[Description("Enable or Disable the plugin functionality")]
[DefaultValue(true)]
public bool Enabled { get; set; }
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
base.PreWebTest(sender, e);
//For TLS
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//For SSL
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
//we wire up the callback so we can override behavior and force it to accept the cert
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCB;
//let them know we made changes to the service point manager
e.WebTest.AddCommentToResult(this.ToString() + " has made the following modification-> ServicePointManager.SecurityProtocol set to use SSLv3 in WebTest Plugin.");
}
public static bool RemoteCertificateValidationCB(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
//If it is really important, validate the certificate issuer here.
//this will accept any certificate
return true;
}
}
关于asp.net - Visual Studio 2013 WebTest 请求失败 : An existing connection was forcibly closed by the remote host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40870624/