A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Thanks for reaching out.
Yes, but check this line:
handler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
This line will accept anything, it won't care about the certificate. It means this will disable all SSL validation, not just disable pinning. This's why your approach to disable the SSL pinning is correct but extremely dangerous.
I recommend a safer approach below:
#if DEBUG
handler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
#endif
This ensures that it's impossible to ship to production accidentally and is safer development workflow.
If your goal is to bypass validation only in UAT while preserving proper validation in production, you may use:
handler.ServerCertificateCustomValidationCallback =
(message, cert, chain, errors) =>
{
if (isUat)
return true;
return errors == SslPolicyErrors.None;
};
This way: UAT bypasses validation and production still validates properly.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well. Thanks for your time.