ohi*_*ano 6 c# asp.net certificate single-page-application
net::ERR_CERT_AUTHORITY_INVALID当我尝试从 SPA 请求 Web API 时,在 ASP.NET Core 中遇到错误。
解决该问题的第一个解决方案是从浏览器访问我的 ASP.NET Core 地址Advanced-Proceed to localhost (unsafe)之后来自我的 SPA 的请求将起作用。但是每次我开始处理我的项目时,我都必须重复这个过程。
我发现的另一个解决方案是这个。简而言之,解决方案是运行命令:dotnet dev-certs https --trust. 我在 Windows 上,所以根据链接的文章On Windows it'll get added to the certificate store。
但是在我运行命令后,我仍然遇到net::ERR_CERT_AUTHORITY_INVALID请求的问题。我能怎么办?
tri*_*ixo 36
按顺序执行此操作
C:\Users\%username%\AppData\Roaming\ASP.NET\https如果你先运行你的项目(第 4 点)。权限不受信任(由3完成)并导致权限无效错误
小智 23
运行该命令dotnet dev-certs https --trust将在您的设备中创建自签名证书。该证书将颁发给该localhost域。就我而言,运行后,证书已创建,但未添加到“受信任的根证书颁发机构”中。

要添加证书,您需要打开certmgr.msc(win+r并运行certmgr.msc),然后转到“个人”证书并将.cer颁发的证书导出到localhost具有正确到期时间的证书。
如果您在那里找不到证书,您可以转到浏览器并单击不安全的连接图标,然后打开无效证书并转到“详细信息”选项卡并单击“复制到文件...”,这也会创建一个.cer证书。

接下来,转到“受信任的根证书颁发机构”并在那里导入证书。完成后,证书将在您的本地计算机中有效。您可能需要重新启动浏览器和服务。
Ome*_*r K 21
就我而言,这有效:
清理旧证书并生成新的受信任证书。运行下面列出的命令:
重新运行应用程序。现在运行应该不会出现 SSL 错误
来源:https ://joeblogs.technology/2021/11/neterr_cert_date_invalid/
在您的应用程序中,通过 NuGet 包添加对 Microsoft.AspNetCore.Authentication.Certificate 的引用。然后在 Startup.ConfigureServices 方法中写入:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(
CertificateAuthenticationDefaults.AuthenticationScheme)
.AddCertificate();
// All other service configuration
}
Run Code Online (Sandbox Code Playgroud)
还要添加 app.UseAuthentication(); 在 Startup.Configure 方法中。否则,HttpContext.User 将不会设置为 ClaimsPrincipal
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseAuthentication();
// All other app configuration
}
Run Code Online (Sandbox Code Playgroud)
来源:https://learn.microsoft.com/en-us/aspnet/core/security/authentication/certauth ?view=aspnetcore-3.1