【问题标题】:401.2 error when trying to authenticate with a client certificate尝试使用客户端证书进行身份验证时出现 401.2 错误
【发布时间】:2014-03-26 18:16:42
【问题描述】:

我正在尝试使用来自 .net 应用程序的客户端证书对网站进行身份验证。

使用相同的证书,我可以使用 chrome 和 IE 访问该站点。在同一台机器上,我得到错误状态代码 401.2。

这是我正在使用的代码:

X509Certificate2 cert2 = new X509Certificate2(x509Cert);
cert2.PrivateKey = algorithm;

if (cert2.Verify() && cert2.HasPrivateKey)
{
    WebRequestHandler handler = new WebRequestHandler();
    handler.ClientCertificates.Add(cert2);
    HttpClient client = new HttpClient(handler);

    string result = await client.GetStringAsync("https://localhost:8443/");
}

编辑:

我现在尝试从证书存储中提取浏览器使用的相同证书,但我仍然收到相同的错误,并且我已切换到使用较旧的 WebClient,我再次收到相同的错误。

任何线索将不胜感激!

谢谢

罗斯

【问题讨论】:

    标签: c# httpclient client-certificates


    【解决方案1】:

    问题不是我的代码,而是 IIS 配置问题。

    浏览器正在工作,因为它们也在发送我的 Windows 凭据 - 我的应用没有这样做,这就是它失败的原因。

    我必须启用将客户端证书映射到 AD:http://www.iis.net/configreference/system.webserver/security/authentication/clientcertificatemappingauthentication

    然后我不得不在网站上禁用 Windows 身份验证。然后应用程序按预期工作。

    【讨论】:

      猜你喜欢
      • 2021-01-16
      • 2012-01-10
      • 2015-10-29
      • 2018-07-05
      • 2019-01-14
      • 2019-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多