這不是一個問題,但需要澄清。這是代碼。所有這些代碼正在發送發送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);
這是一個非常大膽的陳述。我只是聲稱以共享模式打開的文件也可以由請求共享模式的其他進程打開。 http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx – 2009-07-22 07:06:12
@Remus Rusanu:我同意;另外一點是File.OpenRead默認爲Read-shared模式。 – Stobor 2009-07-23 00:41:41