Take the 2-minute tour ×

I set up a FTP server in IIS with an SSL certificate which I created my self (using Makecert.exe and Pvk2Pfx). I attributed the PFX file to my FTP server.

I have a C# script which connects to the FTP server and always gets the following error message:


I installed the certificate in the "Trusted Root Certification Authorities" in the local computer and user.

As it does not authenticate, I took a look via C# on the store:

X509Store store = new X509Store(StoreName.AuthRoot, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

foreach (X509Certificate2 mCert in store.Certificates)
     var friendlyName = mCert.Issuer;

But my certificate is not listed. When I open the MMC console I see my certificate.

share|improve this question
What reason does it give for not trusting? –  Ben Jun 26 '12 at 12:58
Did the answer help you? If so, please accept the answer, if not add info to clarify. –  Sascha Jun 29 '12 at 7:48
I'm sorry Sascha but I can't answer you right away. I'm busy on another project which was priorities. I'll clarify as soon as I can. Thank you for your help. –  Jeppen Jun 29 '12 at 11:56

2 Answers 2

Usually, C# doesn't trust certificates without a trusted root certificate - like in the case of a self-signed certificate. The ServicePointManagerallows to add a function where you can handle trusts yourself.

// Callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(
    object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors policyErrors)
    if (Convert.ToBoolean(ConfigurationManager.AppSettings["IgnoreSslErrors"]))
        // Allow any old dodgy certificate...
        return true;
        return policyErrors == SslPolicyErrors.None;

private static string MakeRequest(string uri, string method, WebProxy proxy)
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
    webRequest.AllowAutoRedirect = true;
    webRequest.Method = method;

    // Allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(

    if (proxy != null)
        webRequest.Proxy = proxy;

    HttpWebResponse response = null;
        response = (HttpWebResponse)webRequest.GetResponse();
        using (Stream s = response.GetResponseStream())
            using (StreamReader sr = new StreamReader(s))
                return sr.ReadToEnd();
        if (response != null)

From blog post How to accept an invalid SSL certificate programmatically.

share|improve this answer

As a quick workaround, you could accept all certificates with:

ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
share|improve this answer

Your Answer


