2011-11-03 81 views
0

我正在使用某些服務並使用服務提供者給出了證書。附加客戶端證書時出現禁止403錯誤

因此,我已經在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開發服務器)運行代碼時,此功能非常完美。

但是,當我在託管這個代碼IIS 7.0它給禁止403錯誤作爲響應。

請建議。

回答

1

你也許應該試試這個:

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

事實證明,誰安裝證書的用戶是自動 授予訪問權限到私鑰,我想你的情況就是你,所以它在開發環境中工作。當Web前端出現時,您不再是ASPNET的用戶。