WPF Core 6. How to temporarily allow (in the code, in debug) to download files from hosting by IP address without SSL?

Volk Volk 551 Reputation points
2022-12-16T12:20:32.893+00:00

Hi!

I have a website in .NET.Core 6 and it works well on runs without SSL on a link with a direct IP address of the type: https:\IP\
Everything works well there, even the files are downloaded from a special Downloads folder.
And I'm currently writing a small application in WPF Core 6 that should download files from this hosting without SSL (from the root or from a specific folder - it doesn't matter).
But when trying to access or download a file, an error related to SSL crashes.

I use these commands:

WebClient webClient = new WebClient();  
Version onlineVersion = new Version(webClient.DownloadString("https://IP/Version.txt"));  

private string gameZip;  
WebClient webClient = new WebClient();  
webClient.DownloadFileAsync(new Uri("https://IP/File.zip"), gameZip);  

271366-error-ssl.png

What code should I use to make downloading from such addresses work without SSL support in order to test the program in the debug or in the release?

I tried to solve the issue in different ways:

Does not work

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;  
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;  

Does not work
How to ignore a certificate error with c# 2.0 WebClient - without the certificate
how-to-ignore-a-certificate-error-with-c-sharp-2-0-webclient-without-the-certi

Interestingly, the code:

try  
            {  
                //Change SSL checks so that all checks pass  
                ServicePointManager.ServerCertificateValidationCallback =  
                   new RemoteCertificateValidationCallback(  
                        delegate  
                        { return true; }  
                    );  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show($"ServicePointManager: {ex}");  
            }  

...showed another error, which was not 404 on the server before. After running this code, my server started sending this error all the time via direct links in the browser, as if this code had remotely forbidden it to do this, although direct links had worked before and I could download files using direct links in the browser. It looks like some kind of mysticism. On the server in MIME-types are allowed .txt and .zip to download.

271357-error-404.png

Now I can't even download the same files via a direct link in the browser... (

Please tell me how I can allow the WPF Core app to download files from a remote hosting by a line like https:\IP \?
I don't need to buy SSL and install it now.

Thanks!

Developer technologies | Windows Presentation Foundation
Developer technologies | ASP.NET | ASP.NET Core
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2022-12-16T16:08:17.373+00:00

    If the website support downloading without ssl, then don’t use ssl in the url, use http:/

    Note: in general it’s better to create a self signed ssl certificate and trust it in the debugging machine

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.