小编The*_*.14的帖子

OnCertificateValidated 未运行 - 自签名证书客户端身份验证 - ASP.NET Core 和 Kestrel

我想使用基于证书的身份验证对连接到在 Kestrel 上运行的 ASP.NET Core Web API (.NET 5) 的客户端进行身份验证。

在我的中,Startup.cs我有以下内容ConfigureServices

services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
    .AddCertificate(options =>
    {
        options.AllowedCertificateTypes = CertificateTypes.All;
        options.Events = new CertificateAuthenticationEvents
        {
            OnCertificateValidated = context =>
            {
                // More code to verify certificates
            },
            OnAuthenticationFailed = context =>
            {
                // More code
            }
        };
    });

// Other services
Run Code Online (Sandbox Code Playgroud)

并在Configure

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthentication();

app.UseEndpoints(endpoints =>
{
    // Endpoints
});
Run Code Online (Sandbox Code Playgroud)

我在其中Program.cs包括:

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthentication();

app.UseEndpoints(endpoints =>
{
    // Endpoints
});
Run Code Online (Sandbox Code Playgroud)

如果我在浏览器中连接到 API,它会提示我输入证书,但在我选择证书后,OnCertificateValidated …

c# client-certificates asp.net-web-api asp.net-core

14
推荐指数
1
解决办法
7189
查看次数