WCF per connection server certificate validation

前端 未结 7 2740
清歌不尽
清歌不尽 2021-02-20 13:50

I\'m trying to bypass https certificate validation only to our own testing environment (multiple machines), while trying to keep certificate validation for all the other connect

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-20 14:12

    I used a flag in the Web.config file to indicate when a certificate is self-signed and we also know that we are in a development environment:

    
    

    In the code we must check this flag to apply the certificate validation exception:

    using System.Net;
    
    bool isSelfSignedCertificate = Convert.ToBoolean(ConfigurationManager.AppSettings["isSelfSignedCertificate"]);
    
    if (isSelfSignedCertificate)
    {
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    }
    

提交回复
热议问题