[英]Connecting to a DO Postgres Cluster on .NET Core with a ca certificate via npgsql
I'm actually using DigitalOcean's Postgres cluster . 我实际上正在使用DigitalOcean的Postgres集群 。 Managed to connect via DataGrip to the server with the credentials I have but I'm facing an auth issue on .NET Core.
设法使用我拥有的凭据通过DataGrip连接到服务器,但是我在.NET Core上遇到身份验证问题。 Apparently, you need to auth with the credentials given + the ca-certificate provided (DigitalOcean provides the CA).
显然,您需要使用给定的凭据+提供的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);
After that, running the project results in: 之后,运行项目将导致:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
What am I doing wrong? 我究竟做错了什么? Really apologise if this isn't enough.
如果还不够,请您深表歉意。
Am on PG 11.4 by the way. 顺便说一句,我在PG 11.4上。
Your server certificate is likely self-signed or cannot be validated for some reason. 您的服务器证书可能是自签名的,或者由于某些原因而无法验证。 You can tell Npgsql to disable checking the server certificate by adding
Trust Server Certificate=true
on the connection string. 您可以通过在连接字符串上添加
Trust Server Certificate=true
来告诉Npgsql禁用检查服务器证书。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.