简体   繁体   English

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

[英]Multiple users accessing certificate file at a time

This is kind of not a question, but need a clarification. 这不是一个问题,但需要澄清。 Here is the code. 这是代码。 All this code is doing is sending sending a cer file to server in httpwebrequest which is placed on a local drive. 这些代码所要做的就是将cer文件发送到位于本地驱动器上的httpwebrequest中的服务器。 My question is, what happens if multiple users try to access the application at a time. 我的问题是,如果多个用户同时尝试访问该应用程序,将会发生什么。 I mean 5-10 requests reading the same cer at a time. 我的意思是5-10次请求一次读取同一cer。 will it break saying that the cer file is locked by some other thread to read/or will it not break because it's just read only? 是否会说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);

读取操作不会在Windows中锁定文件。

Why not send the certificate from the user store instead of file and eliminate the concern, as in the second method described in How to send a client certificate by using the HttpWebRequest . 为什么不从用户存储而不是从文件发送证书,并消除这种担忧,如如何使用HttpWebRequest发送客户端证书中描述的第二种方法中所述。 You need to load the private key into the key store anyway, so I really don't see any point in using the certificate from a .cer file. 无论如何,您都需要将私钥加载到密钥存储中,所以我真的看不到使用.cer文件中的证书的任何意义。

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

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