2017-10-04 2 views
-1

테스트 서버에 응용 프로그램을 배포 할 때 MongoDB 드라이버를 사용하여 Cosmos DB에 연결할 수 없습니다.MongoDB 드라이버를 사용하여 Azure Cosmos DB에 연결할 수 없음 .Net C#

우리의 모든 개발 기계는 문제가 없지만 테스트에서 다음과 같은 결과를 얻고 있습니다. 나는 기계에 관한 인증서를 가지고 그 문제를 얻었지만 어떻게 해결할 수 있습니까?

[{ ServerId: "{ ClusterId : 1, EndPoint : 
"Unspecified/xxxxxxxxx.documents.azure.com:10255" }", 
EndPoint: "Unspecified/xxxxxxxx.documents.azure.com:10255", 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. 

여기서 클라이언트 인증서가 유효하지 않습니까?

우리는 아무 문제없이 Azure SQL 인스턴스에 연결할 수 있습니다.

답변

0

서버 인증서 유효성 검사에 대한 자세한 내용을 확인하고이 오류를 줄이려면 정책 오류를 확인하려면 SslSettings.ServerCertificateValidationCallback을 사용할 수 있습니다. 다음과 같이 MongoClientSettings을 작성하여 MongoClient을 구축 할 수 있습니다.

MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl("{connection-string-of-your-cosmosdb}")); 
settings.SslSettings = new SslSettings() 
{ 
    EnabledSslProtocols = SslProtocols.Tls12, 
    ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
    { 
     foreach (var element in chain.ChainElements) 
     { 
      // Gets the error status of the current X.509 certificate in a chain. 
      foreach (var status in element.ChainElementStatus) 
      { 
       Console.WriteLine($"certificate subject: {element.Certificate.Subject},ChainStatus: {status.StatusInformation}"); 
      } 
     } 
     return true; //just for dev, it would bypass certificate errors 
    } 
}; 
var mongoClient = new MongoClient(settings);