Dotnet Tutorials ,Codings & Examples: The remote certificate is invalid <h1 class='display-2'> The remote certificate is invalid ~ Dotnet Tutorials ,Codings & Examples</h1>

The remote certificate is invalid

The remote certificate is invalid according to the validation procedure

you will get this error because of certificates issue while getting the response from the external web service or any other Web Request from the server.

follow the below snippet to resolve this issue

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

protected void Page_Load(object sender, EventArgs e)


      ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCB;

      Uri uri = new Uri("");

      if (uri.Scheme == Uri.UriSchemeHttp)


       HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);

       request.Method = WebRequestMethods.Http.Get;

       HttpWebResponse response = (HttpWebResponse)request.GetResponse();

StreamReader reader = new StreamReader(response.GetResponseStream());     

       string tmp = reader.ReadToEnd();







public static bool RemoteCertificateValidationCB(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)


        //If it is really important, validate the certificate issuer here.

        string resultsTrue = certificate.Issuer.ToString();

        //For now, accept any certificate

        return true;



thanks for ur comment . i will publish more useful articles in this blog

Post a Comment