You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IIS中浏览器客户端证书弹窗问题:如何读取智能卡证书?

问题描述

我需要从浏览器读取智能卡读卡器中的证书,并用该证书调用外部服务API。已搭建ASP.NET API项目,代码如下:

[HttpGet]
public async Task<ActionResult> Get()
{
    var cert = await HttpContext.Connection.GetClientCertificateAsync();
    // call external service
    return Ok();
}

同时在applicationHost.config中添加了以下配置:

<section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Allow" />

<security>
    <access sslFlags="Ssl, SslNegotiateCert, SslRequireCert" />
    <authentication>
        <anonymousAuthentication enabled="false" />
        <basicAuthentication enabled="false" />
        <clientCertificateMappingAuthentication enabled="true" />
        <digestAuthentication enabled="false" />
        <iisClientCertificateMappingAuthentication enabled="true">
        </iisClientCertificateMappingAuthentication>
</security>

调用端点时出现错误:

HTTP Error 403.7 - Forbidden
The page you are attempting to access requires your browser to have a Secure Sockets
Layer (SSL) client certificate that the Web server recognizes.

请问如何让浏览器弹出提示读取智能卡中的客户端证书?是否需要在本地安装证书?


解决方案
  • 先确认服务器SSL证书的有效性:当前sslFlags设置了SslRequireCert,但必须保证服务器的SSL证书受浏览器信任——要么是正规CA签发的,要么已将其根证书导入浏览器的信任根存储。如果服务器证书不受信任,浏览器会直接阻止证书选择弹窗。
  • 智能卡基础配置:
    • 不需要在本地安装智能卡上的证书,但必须安装智能卡读卡器的驱动程序以及对应智能卡的PKCS#11中间件,这样浏览器才能识别到智能卡设备。
    • 确认智能卡已正确插入读卡器,且系统能识别到智能卡中的证书(可通过Windows「证书管理器」-「个人」目录查看是否有对应条目)。
  • 浏览器端设置:
    • Chrome/Edge:进入「设置-隐私和安全性-安全-高级-管理证书」,确认智能卡的证书已被识别;同时确保站点HTTPS连接有效,浏览器未标记为不安全。
    • Firefox:在about:config中将security.osclientcerts.autoload设为true,并确认智能卡驱动已正确加载。
  • IIS配置调整:
    • 当前同时启用了clientCertificateMappingAuthentication和iisClientCertificateMappingAuthentication,如果不需要做证书到用户的映射,只是要获取证书,可暂时关闭iisClientCertificateMappingAuthentication,仅保留clientCertificateMappingAuthentication启用状态。
    • 在IIS管理器的站点SSL设置中,确认「要求SSL」和「要求客户端证书」已勾选,客户端证书选项设为「接受」或「要求」(选「忽略」不会触发证书选择)。
  • 服务器端证书信任:要将智能卡证书的根CA证书导入到服务器的「受信任的根证书颁发机构」存储中,否则服务器会判定证书不合法,返回403.7错误。

内容的提问来源于stack exchange,提问作者ThunderDev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 10:20:43