【发布时间】:2017-05-25 10:26:12
【问题描述】:
我们有 2 台 Web 服务器提供负载平衡服务。每个 IIS 主机都有一个临时文件夹 D:\Website\PTSMAM\UploadFolder\ 用于放置上传的文件。当用户提交上传文件时,它会将文件上传到 UploadFolder,然后将上传的文件移动到永久存储中。碰巧,如果用户的请求是直接到Server1,它得到了以下异常
System.IO.FileNotFoundException:找不到文件 'D:\Website\PTSMAM\UploadFolder\G201323200010081.txt'。文件名: 'D:\Website\PTSMAM\UploadFolder\G201323200010081.txt' 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.File.Move(String sourceFileName, String destFileName)
在 PTS_MAM3.Web.DataSource.WSARCHIVE.fileMove(ClassUploadFileClass x, 字符串大小写)在 E:\PTSMAM_Source\PTS_MAM\PTS_MAM3.Web\DataSource\WSARCHIVE.asmx.cs:line 第1655章
但文件夹中存在“D:\Website\PTSMAM\UploadFolder\G201323200010081.txt”文件。
如果我在 Server2 中进行上传工作,它工作正常。 这是为什么? Server1:D:\Website\PTSMAM\UploadFolder 和 Server2:D:\Website\PTSMAM\UploadFolder 是否可能不同?
以下是源代码。 我认为异常是由 System.IO.File.Move(fileFrom, fileDest);
private bool fileMove(ClassUploadFileClass x, string scase)
{
string fileFrom = string.Empty;
string fileFromV = string.Empty;
string fileDest = x.strDirectory;
//string fileDest2 = string.Concat(System.IO.Path.GetDirectoryName(fileDest), @"\", System.IO.Path.GetFileNameWithoutExtension(fileDest), "_M", System.IO.Path.GetExtension(fileDest));
string fileDest2 = string.Concat(System.IO.Path.GetDirectoryName(fileDest), @"\", System.IO.Path.GetFileNameWithoutExtension(fileDest), "_M.jpg");
string TempDir = Server.MapPath("/") + @"UploadFolder\";
//MAM_PTS_DLL.SysConfig obj = new MAM_PTS_DLL.SysConfig();
//string dirPhoto = obj.sysConfig_Read("/ServerConfig/STO_Config/UPLOAD_FOLDER_PHOTO");
//string dirDoc = obj.sysConfig_Read("/ServerConfig/STO_Config/UPLOAD_FOLDER_DOC");
//string dirAudio = obj.sysConfig_Read("/ServerConfig/STO_Config/UPLOAD_FOLDER_AUDIO");
try
{
//MAM_PTS_DLL.Log.AppendTrackingLog("WSARchive/fileMove", MAM_PTS_DLL.Log.TRACKING_LEVEL.INFO, "Path = " + fileDest);// + @"\" + x.strFileId + "." + x.strOExtensionName);
switch (scase)
{
case ("Photo"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);//@"\\10.13.220.2\uploadfolder\Pictures\"
//fileFromV = string.Concat(TempDir, x.strFileId, "_M.", x.strOExtensionName);//@"\\10.13.220.2\uploadfolder\Pictures\"
fileFromV = string.Concat(TempDir, x.strFileId, "_M.jpg");
break;
case ("Audio"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);//@"\\10.13.220.2\uploadfolder\Audios\"
break;
case ("Doc"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);
break;
case ("LowVideo"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);
break;
}
string dirPath = System.IO.Path.GetDirectoryName(fileDest);
if (!System.IO.Directory.Exists(dirPath))
System.IO.Directory.CreateDirectory(dirPath);
System.IO.File.Move(fileFrom, fileDest); // + @"\" + x.strFileId + "." + x.strOExtensionName);
if (scase == "Photo")
System.IO.File.Move(fileFromV, fileDest2);
return true;
}
catch (Exception ex)
{
MAM_PTS_DLL.Log.AppendTrackingLog("File Move Problem", MAM_PTS_DLL.Log.TRACKING_LEVEL.ERROR, x.strOFileName + ",ex = " + ex.ToString());
return false;
}
}
【问题讨论】: