MongoDB远程服务器连接问题

时间:2018-12-05 18:19:46

标签: mongodb

无法使用证书连接到MongoDB远程服务器。低于错误。 $ exception {“无法连接到服务器dcdmongo.nt.lab.com:27017:无法验证'CN = DistExp.nt.lab.com,OU = IT,O = MyCompanyIncorporated,L = KOP,C = US @ $外部,ST = PA”(使用'MONGODB-X509'..“} MongoDB.Driver.MongoConnectionException。

这是代码

var cert = new X509Certificate2(@"C:\VS2017\WebAPIMongoDB\Students.DataModel\DistributionExpansion.nt.lab.com.pfx", "mypassword");

        var settings = new MongoClientSettings
        {
            Credentials = new[]
            {
                MongoCredential.CreateMongoX509Credential("CN=DistExp.nt.lab.com,OU=IT,O=MyCompanyIncorporated,L=KOP,ST=PA,C=US@$external")
            },
            SslSettings = new SslSettings
            {
                ClientCertificates = new[] { cert },
            },
            UseSsl = true,


        };
        settings.Server = new MongoServerAddress("dcdmongo.nt.lab.com");
        settings.SslSettings.CheckCertificateRevocation = false;
        settings.VerifySslCertificate = false;          
        var client = new MongoClient(settings);
        var server = client.GetServer();
        if (server.State == MongoServerState.Disconnected)
            server.Connect();

0 个答案:

没有答案