Why ServicePointManager isn't recommended for new developments

1.2k Views Asked by At

I'm trying to intercept the validation of the returned server certificates in a .net framework application. I came with two solutions:

  1. Use HttpClientHandler.ServerCertificateValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) =>{ my implementation}

  2. Use ServicePointManager.ServerCertificateValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) =>{ my implementation}

Is there advantage for the use of one on another?

From the article it says

We don't recommend that you use the ServicePointManager class for new development. Instead, use the System.Net.Http.HttpClient class.

Is there any reason for that , other than ServicePointManager not being used in .net Core?

1

There are 1 best solutions below

0
YungDeiza On

ServicePointManager seems to have a few methods marked as obsolete: https://learn.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager?view=net-6.0#:~:text=this%20ServicePointManager%20object.-,Methods,-Equals(Object)

Looks like new classed with updated methods now exist. ServicePointManager is probably being kept around largely for compatibility with old versions.