我有一個ASP.NET的Web應用程序,它具有以下功能:ASP.NET信息:System.UnauthorizedAccessException - 訪問路徑被拒絕
- 讀取Excel文件。
- 該excel文件將有一個圖像URL位於它指向互聯網上的某個地方。
- 該程序讀取每個圖像的URL並將其存儲到Web服務器的臨時文件夾中。
- 然後應用程序調整大小(更改圖像的寬度和高度)。
最後,應用程序會將該圖像保存到另一個文件夾。
我得到以下異常:
System.Net.WebException:一個異常 一個Web客戶端請求期間發生。 ---> System.UnauthorizedAccessException: 訪問路徑 '\ abcserver \ target03 \ 3111 \ 35644 \ www.testing.com \ web \ content \ images \ TempStorage \ tempImage.jpg' 被拒絕。在 System.IO .__ Error.WinIOError(的Int32 的errorCode,字符串maybeFullPath)在 System.IO.FileStream.Init(字符串路徑, 的FileMode模式,FileAccess的訪問, 的Int32權利,布爾useRights, 文件共享份額,緩衝區大小的Int32 , FileOptions選項, SECURITY_ATTRIBUTES secAttrs,字符串 MSGPATH,布爾bFromProxy)在 System.IO.FileStream..ctor(字符串 路徑,的FileMode模式,FileAccess的 訪問)在 System.Net.WebClient.DownloadFile(URI 地址,字符串文件名)---結束內部異常堆棧跟蹤 ---
在ProcessImage.GetFileFromUrl(字符串 imageFileUrl,字符串newFileName)
在 uploadexceldata.UploadExcelData(字符串 文件名)
foreach (DataRow dr in dt.Rows) // Reading each excel row
{
if (dr[0].ToString() != "")
{
id= "";
path = "";
manuId = "";
id= dr[0].ToString();
path = dr[1].ToString();
fileNameOnly = iProImg.GetFileNameOnly(path);
objDb.openConnection();
strSqlGroupInfo = "select ManufacturerID from manufacturers where id='" + id+ "'";
dTblManu = objDb.BuildDT(strSqlGroupInfo); // To Fill data to Datatable
objDb.closeConnection();
if (dTblManu.Rows.Count > 0)
{
manuId = dTblManu.Rows[0][0].ToString();
}
if (manuId != "")
{
tempUploadPath = "images/TempStorage/";
tempUploadPath = Server.MapPath(tempUploadPath);
if (!Directory.Exists(tempUploadPath))
{
Directory.CreateDirectory(tempUploadPath);
}
tempFilePath = tempUploadPath + "\\tempImage.jpg";
tempFilePath = tempFilePath.Replace("/", "\\");
previewPath = Server.MapPath("images/previews/" + manuId);
thumbNailPath = Server.MapPath("images/thumbnails/" + manuId);
if (!Directory.Exists(previewPath))
{
Directory.CreateDirectory(previewPath);
}
if (!Directory.Exists(thumbNailPath))
{
Directory.CreateDirectory(thumbNailPath);
}
fileNameOnly = "\\preview" + id+ ".jpg";
fileNameOnly = fileNameOnly.Replace("/", "\\");
previewPath = previewPath + fileNameOnly;
tempPartialPathP = "images\\previews\\" + manuId + fileNameOnly;
fileNameOnly = "\\thumbnail" + id+ ".jpg";
thumbNailPath = thumbNailPath + fileNameOnly;
tempPartialPathT = "images\\thumbnails\\" + manuId + fileNameOnly;
try
{
iProImg.GetFileFromUrl(path, tempFilePath);
rowCounter++;
iProImg.ReSizeImage(tempFilePath, previewPath, previewSize);
iProImg.ReSizeImage(previewPath, thumbNailPath, thumbNailSize);
}
catch (Exception ec)
{
errorRowCount++;
iLog.LogErrorToFile("uploadExcel", ec.ToString(), "path : " + path + ",tempFilePath :" + tempFilePath);
}
finally
{
if(File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
}
}
} // If manuid!=""
} //if (dr[0].ToString() != "")
有沒有人對如何解決這個例外有什麼建議?
任何爲.NET用戶設置「完全控制」權限的腳本? – Kiquenet 2011-11-22 11:00:07
我有同樣的問題 - 這是我的臨時目錄,沒有適當的權限... – bgmCoder 2012-07-02 22:54:13