繁体   English   中英

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

[英]Forbidden 403 error when attaching client certificate

我正在使用某些服务,并且正在使用服务提供者提供的证书。

因此,我已在LocalMachine上安装了证书,并通过以下代码将证书与要发布的Web请求附加在一起,以获取Web服务的响应。

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错误作为响应。

请提出建议。

您也许应该尝试以下方法:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM