多个用户一次访问证书文件

时间:2009-07-22 00:43:34

标签: c# certificate

这不是一个问题,但需要澄清。这是代码。所有这些代码都在发送一个cer文件发送到httpwebrequest中的服务器,该文件放在本地驱动器上。我的问题是,如果多个用户一次尝试访问该应用程序会发生什么。我的意思是一次读取同一个cer的5-10个请求。它是否会破坏说某个其他线程要锁定cer文件/或者它是否会因为它只是只读而中断?

//You must change the path to point to your .cer file location. 
X509Certificate Cert = X509Certificate.CreateFromCertFile("C:\\mycert.cer");
// Handle any certificate errors on the certificate from the server.
ServicePointManager.CertificatePolicy = new CertPolicy();
// You must change the URL to point to your Web server.
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://YourServer/sample.asp");
Request.ClientCertificates.Add(Cert);
Request.UserAgent = "Client Cert Sample";
Request.Method = "GET";
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
// Print the repsonse headers.
Console.WriteLine("{0}",Response.Headers);
Console.WriteLine();
// Get the certificate data.
StreamReader sr = new StreamReader(Response.GetResponseStream(), Encoding.Default);
int count;
char [] ReadBuf = new char[1024];
do
{
    count = sr.Read(ReadBuf, 0, 1024);
    if (0 != count)
    {
        Console.WriteLine(new string(ReadBuf));
    }

}while(count > 0);

2 个答案:

答案 0 :(得分:1)

读取不会锁定Windows中的文件....

答案 1 :(得分:0)

为什么不从用户存储而不是文件发送证书并消除问题,如How to send a client certificate by using the HttpWebRequest中描述的第二种方法。无论如何,您需要将私钥加载到密钥存储区中,因此我在使用.cer文件中的证书时看不到任何意义。