Nic*_*las 4 postgresql npgsql digital-ocean .net-core
我实际上在使用DigitalOcean 的 Postgres 集群。设法使用我拥有的凭据通过 DataGrip 连接到服务器,但我在 .NET Core 上遇到了身份验证问题。显然,您需要使用给定的凭据 + 提供的 ca 证书(DigitalOcean 提供 CA)进行身份验证。
services.AddDbContext<NozomiDbContext>(options =>
{
options.UseNpgsql(mainDb
, builder =>
{
builder.EnableRetryOnFailure();
builder.ProvideClientCertificatesCallback(certificates =>
{
var cert = new X509Certificate2("ca-certificate.crt");
certificates.Add(cert);
});
}
);
options.EnableSensitiveDataLogging(false);
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
}, ServiceLifetime.Transient);
Run Code Online (Sandbox Code Playgroud)
之后,运行项目的结果是:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?如果这还不够,真的很抱歉。
顺便说一下,我在 PG 11.4 上。
您的服务器证书可能是自签名的或由于某种原因无法验证。您可以通过添加Trust Server Certificate=true连接字符串来告诉 Npgsql 禁用检查服务器证书。