2

I'm building a ASP.Net Core 2.2 MVC website and I'm using AzureAD as login. Also I'm using a bearer token to get data from a Microsoft Dynamics backend.

Everything worked fine and I got my data until yesterday. I got an IIS error (visual studio debug mode) that said that it cannot find connection and timed out after around 5 million milliseconds (it was around 5-6 real seconds). I restarted my computer and I wasn't getting that error again but since then I'm getting this error while getting my data:

The SSL connection could not be established, see inner exception. The remote certificate is invalid according to the validation procedure

I didn't change any code from when it worked till when it didn't anymore. I hope you guys can help me. If you need further informations please let me know and I'll provide them.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Myridor
  • 123
  • 3
  • 15
  • The error is clear - you're trying to connect to a server whose certificate is invalid. Restarting your machine won't fix anything. The real solution is to use a valid certificate on that server, or at least trust the server's certificate. The "hack" is to bypass certificate validation. – Panagiotis Kanavos Mar 22 '19 at 10:11
  • Please post the *code* that throws this error. There are many ways to configure certificate validation, eg for the entire application or for specific HttpClient instances. [This question](https://stackoverflow.com/questions/38138952/bypass-invalid-ssl-certificate-in-net-core) shows several options. – Panagiotis Kanavos Mar 22 '19 at 10:13
  • The thing is in my ASP.Net website its working fine, same code, same server. It's throwing the error in this line: `using (var response = (HttpWebResponse)request.GetResponse())` – Myridor Mar 22 '19 at 10:17
  • This has nothing to do with whether the site works or not. I suspect the browser displays a certificate warning though. If you try to connect to a service using SSL and the server's certificate is invalid, you get that error. If the certificate isn't trusted by your computer, you get the same error. Self-signed developer certificates *aren't* trusted so they cause that error. – Panagiotis Kanavos Mar 22 '19 at 10:24
  • If the problem is caused when calling your ASP.NET Core service, check [Developing locally with ASP.NET Core under HTTPS, SSL, and Self-Signed Certs](https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx). You can easily add a development certificate to the list of trusted certificates on your machine with `dotnet dev-certs https --trust` – Panagiotis Kanavos Mar 22 '19 at 10:25

0 Answers0