Reputation: 5
We upgraded from windows server 2012 to windows server 2019. I'm using webclient to download images during a user session. Use to work perfectly and works locally when I run it. When I move the source code to windows server 2019 it fails with the standard The underlying connection was closed:
Using .Net 4.6 Using Security Protocol Tls12. I'm extremely baffled by what is causing the issue
ServicePointManager.Expect100Continue = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
using (var web_client = new WebClient())
{
web_client.DownloadFile(file_url, download_file_path_with_name);
}
Does anyone have some other suggestions. I tried with Exter100Continue = true with same results.
Upvotes: 0
Views: 224
Reputation: 319
If you set a user agent in your web client instance would it have worked?
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299"
Upvotes: 0
Reputation: 1025
There are some big changes in the versions and cipher suites from 2012 to 2019.
First: I would recommend that you just allow the OS to decide which Security Protocol to use (it will negotiate TLS version and cipher suite with the server that hosts your image). Here is a good article about TLS versioning and .NET versions and OS versions
Second: I would run something like Fiddler locally on your server to see where the web request is failing (I'm guessing the TLS handshake fails). Fiddler will provide alot more detail about your web requests at the packet level.
Upvotes: 3