繁体   English   中英

MongoDB C#驱动程序“远程证书无效”

[英]MongoDB C# Driver 'Remote certificate is invalid'

我在使用C#驱动程序连接到MongoDB时遇到问题。 该代码可在其他系统上运行,但由于某些原因不希望在我的系统上运行。 我正在使用最新的Mongo .net驱动程序和core / bson,并且具有正确的连接设置。

我的完整错误是:

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode = Primary, TagSets = [] } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Sharded", Type : "Sharded", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/lon-mongos1.objectrocket.com:33138" }", EndPoint: "Unspecified/lon-mongos1.objectrocket.com:33138", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
 at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
 at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
 at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
 at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
 at MongoDB.Driver.Core.Connections.SslStreamFactory.<CreateStreamAsync>d__4.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
 at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__47.MoveNext()
 --- End of inner exception stack trace ---
 at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__47.MoveNext()
 --- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
 at MongoDB.Driver.Core.Servers.ClusterableServer.<HeartbeatAsync>d__42.MoveNext()" }] }.

我已经在本地查看了证书,但是看不到任何表明它对我无效的信息。

我来自非蒙古族背景,这不是我太熟悉的事情,但是想知道是否有人可以阐明我在这里做错了什么?

我正在运行VS2015的W7 SP1。

编辑:无论如何,我都尝试过验证证书的方法,但这也没有证明有任何不同。

我确实定期运行小提琴手,但是我已经删除了小提琴手的证书,并且目前我没有在运行它。

在大多数情况下,当MongoDb使用自签名SSL证书并且无法通过本地安装的根证书通过标准验证时,会出现此错误。 您可以通过在连接字符串中指定以下查询参数来简单地禁用此验证:

sslVerifyCertificate=false

如果使用c#代码配置MongoDb驱动程序:

var client = new MongoClient();
client.Settings.VerifySslCertificate = false;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM