2009-07-22 56 views
0

這不是一個問題,但需要澄清。這是代碼。所有這些代碼正在發送發送cer文件到httpwebrequest中的服務器,該文件放置在本地驅動器上。我的問題是,如果多個用戶一次嘗試訪問應用程序會發生什麼情況。我的意思是一次讀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); 

回答

0

爲什麼不把從用戶存儲,而不是文件中的證書和消除顧慮,如在How to send a client certificate by using the HttpWebRequest描述了第二種方法。無論如何,您需要將私鑰加載到密鑰存儲區,所以我真的沒有看到使用.cer文件中的證書的任何一點。

1

讀取數據並不會在Windows鎖定文件....

+0

這是一個非常大膽的陳述。我只是聲稱以共享模式打開的文件也可以由請求共享模式的其他進程打開。 http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx – 2009-07-22 07:06:12

+0

@Remus Rusanu:我同意;另外一點是File.OpenRead默認爲Read-shared模式。 – Stobor 2009-07-23 00:41:41