附加客户端证书时出现403错误

时间:2011-11-03 10:31:19

标签: asp.net security iis-7 ssl ssl-certificate

我正在使用某些服务并且使用服务提供商已经提供了证书。

所以我已经在 LocalMachine 上安装了证书,并通过以下代码将证书与我发布的网页请求相关联,以便从网络服务获得回复。

X509Certificate cert = null;
string ResponseXml = string.Empty;

// Represents an X.509 store, which is a physical store
// where certificates are persisted and managed 
X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);

certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection results =
    certStore.Certificates.Find(X509FindType.FindBySubjectDistinguishedName,
                                Constants.CertificateName, false);
certStore.Close();

if (results != null && results.Count > 0)
    cert = results[0];
else
{
    ErrorMessage = "Certificate not found";
    return ErrorMessage;
}
webClient.TransportSettings.ClientCertificates.Add(cert);

当我使用ASP.net Cassini(ASP.NET Developement Server)运行代码时,这非常有效。

但是当我在 IIS 7.0 中托管此代码时,它会将禁止403 错误作为回复。

请建议。

1 个答案:

答案 0 :(得分:1)

你应该试试这个:

winhttpcertcfg -g -c LOCAL_MACHINE \ MY -s(MyCertificate)-a ASPNET

事实证明,安装证书的用户是自动的 授权访问私钥,我想你的情况就是你,所以它在开发环境中工作。当Web前端出现时,您不再是用户,ASPNET就是。

相关问题