C#:无法在IIS上创建SSL/TLS安全通道
我有一个从internet explorer导出为.cer文件的证书,我使用它使用c#连接网站,该连接在使用iis express的visual studio上工作正常,但切换到iis时返回错误 错误:无法创建SSL/TLS安全通道,某个时间返回:无法从传输连接读取数据:远程主机强制关闭了现有连接 那么,为什么它在iis express上运行良好,而不是在iis上运行良好呢 备注:证书文件没有私钥C#:无法在IIS上创建SSL/TLS安全通道,c#,ssl,C#,Ssl,我有一个从internet explorer导出为.cer文件的证书,我使用它使用c#连接网站,该连接在使用iis express的visual studio上工作正常,但切换到iis时返回错误 错误:无法创建SSL/TLS安全通道,某个时间返回:无法从传输连接读取数据:远程主机强制关闭了现有连接 那么,为什么它在iis express上运行良好,而不是在iis上运行良好呢 备注:证书文件没有私钥 X509Certificate2Collection certificates =
X509Certificate2Collection certificates = new X509Certificate2Collection();
certificates.Import(this._certName, this._certPass, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
byte[] data = null;
if (method == (int)Method.POST)
{
ASCIIEncoding encoding = new ASCIIEncoding();
data = encoding.GetBytes(post);
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this._baseUrl + path);
request.Method = method == (int)Method.POST ? "POST" : "GET";
if (method == (int)Method.POST)
{
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
}
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.ClientCertificates = certificates;
request.Proxy = WebRequest.DefaultWebProxy;
request.Credentials = System.Net.CredentialCache.DefaultCredentials; ;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
if (this._sessionId != null) {
request.Headers.Set("Cookie", this._sessionId);
}
Stream newStream;
if (method == (int)Method.POST)
{
newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
试试这个:谢谢你的回复freshbm,我尝试了网络上的所有建议,但都失败了,我认为这是一个权限问题,但我不知道如何解决它。web中的所有解决方案都是使用winhttpcertcfg授予访问权限,但由于缺少私钥并且需要.pfx文件,因此无法工作。