Tom Regan
Tom Regan

Reputation: 3851

Visual Studio 2013 WebTest Request Failed: An existing connection was forcibly closed by the remote host

I'm attempting to run a Visual Studio 2013 web test on my local machine. This is a test that I've run successfully (the last time about 2 months ago). The first step in the web test is a GET request to a login page. It looks like this:

GET https://example.com/Login.aspx

When I type this url into a web browser it succeeds. Also, I can successfully record a web test where I merely navigate to this page and log in. But when I attempt to re-run the webtest that I just recorded I get this response to the GET request:

Request failed: An existing connection was forcibly closed by the remote host

Nothing is logged by IIS on example.com (IIS does not log the GET request). But, when I manually log in, or when I record the web test, IIS does log the GET request properly.

There are no messages logged in the event viewer on example.com or on my local host.

Any suggestions on how to debug this issue are much appreciated.

Upvotes: 2

Views: 3576

Answers (3)

Miguel
Miguel

Reputation: 1714

Visual Studio 2019 - Load Test

  • Scenario: Using unit test for the load test.
  • Problem: When running the unit test manually it runs without problems. As soon as the load test starts it fails with same error: "An existing connection was forcibly closed by the remote host".
  • Solution: Force TLS1.2 when initializing the unit test.
[TestInitialize]
public void Init()
{
  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
}

Upvotes: 0

daya-shankar07
daya-shankar07

Reputation: 76

Today I faced a similar problem with Visual Studio 2017 Enterprise and after a couple of hours, able to resolve it. I added below two registry keys in my machine where Visual Studio is installed and it resolved the issue. For a complete description of setting, Refer documentation:- https://support.microsoft.com/en-in/help/4040243/how-to-enable-tls-1-2-for-configuration-manager

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319] "SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319] "SchUseStrongCrypto"=dword:00000001

Two entries of SchUseStrongCrypto key needs to be done in the registry just like below snapshot.

**SchUseStrongCrypto** needs to be added in 2 paths just like below snapshot

Upvotes: 2

dimaaan
dimaaan

Reputation: 916

For me, the problem was a TLS handshake. Solved by adding a plug-in to web test.

Think is original question, that helps me: https://social.msdn.microsoft.com/Forums/vstudio/en-US/bc3ebf23-575d-4e54-bd6b-a1ed87fe5213/web-performance-test-is-not-working-with-tls12-enabled?forum=vstest

Plugin source:

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;
    }
}

Upvotes: 6

Related Questions