ASP.NET信息:System.UnauthorizedAccessException - 访问路径被拒绝 [英] ASP.NET: System.UnauthorizedAccessException - Access to Path Denied
问题描述
我有一个ASP.NET的Web应用程序,执行以下操作:
- 读取Excel文件。
- Excel文件将位于它的图像URL指向互联网上的某个地方。
- 程序读取每个图像URL和存储到Web服务器的临时文件夹。
- 然后调整应用程序(改变宽度和高度)的形象。
-
最后,应用程序会将该图像保存到另一个文件夹。
我收到以下异常:
System.Net.WebException:一个异常
一个Web客户端请求期间发生的。
---> System.UnauthorizedAccessException的:
访问路径
'\\ abcserver \\ target03 \\ 3111 \\ 35644 \\ www.testing.com \\网络\\内容\\影像\\ TempStorage \\ tempImage.jpg
被拒绝。在
System.IO .__ Error.WinIOError(的Int32
错误code,字符串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(在dt.Rows的DataRow DR)//读取每个练成一行
{ 如果(DR [0]的ToString()!=)
{
ID =;
路径=;
manuId =;
ID =博士[0]的ToString();
PATH =博士[1]的ToString();
fileNameOnly = iProImg.GetFileNameOnly(路径);
objDb.openConnection();
strSqlGroupInfo ='+ ID +,从厂家其中id =选择ManufacturerID'; dTblManu = objDb.BuildDT(strSqlGroupInfo); //要填写数据的DataTable
objDb.closeConnection();
如果(dTblManu.Rows.Count大于0)
{
manuId = dTblManu.Rows [0] [0]的ToString();
} 如果(manuId!=)
{
tempUploadPath =图像/ TempStorage /;
tempUploadPath =使用Server.Mappath(tempUploadPath);
如果(!Directory.Exists(tempUploadPath))
{
Directory.CreateDirectory(tempUploadPath);
}
tempFilePath = tempUploadPath +\\\\ tempImage.jpg
tempFilePath = tempFilePath.Replace(/,\\\\); previewPath =使用Server.Mappath(图像/ previews /+ manuId);
thumbNailPath =使用Server.Mappath(图像/缩略图/+ manuId); 如果(!Directory.Exists(previewPath))
{
Directory.CreateDirectory(previewPath);
}
如果(!Directory.Exists(thumbNailPath))
{
Directory.CreateDirectory(thumbNailPath);
}
fileNameOnly =\\\\ preVIEW+身份证+.JPG;
fileNameOnly = fileNameOnly.Replace(/,\\\\);
previewPath = previewPath + fileNameOnly;
tempPartialPathP =图片\\\\ previews \\\\+ manuId + fileNameOnly; fileNameOnly =\\\\缩略图+身份证+.JPG;
thumbNailPath = thumbNailPath + fileNameOnly;
tempPartialPathT =图片缩略图\\\\ \\\\+ manuId + fileNameOnly;
尝试
{ iProImg.GetFileFromUrl(路径,tempFilePath);
rowCounter ++;
iProImg.ReSizeImage(tempFilePath,previewPath,previewSize);
iProImg.ReSizeImage(previewPath,thumbNailPath,thumbNailSize); }
赶上(例外EC)
{ errorRowCount ++;
iLog.LogErrorToFile(uploadExcel,ec.ToString(),路径:+路径+,tempFilePath:+ tempFilePath);
}
最后
{
如果(File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
}
}
} //如果manuid!=
} //如果(DR [0]的ToString()!=)有没有人对如何解决这个例外?任何建议
解决方案尝试设置访问权限为完全控制为.NET用户从那里你正在阅读/保存的文件。
I have an ASP.NET web application which does the following:
- Reads an Excel file.
- The excel file will have an image URL located in it that points to somewhere on the internet.
- The program reads each image URL and store it into a temporary folder in the web server.
- The application then resizes (changes the width and height) of the image.
Finally, the application will save that image to another folder.
I am getting the following exception:
System.Net.WebException: An exception occurred during a WebClient request. ---> System.UnauthorizedAccessException: Access to the path '\abcserver\target03\3111\35644\www.testing.com\web\content\images\TempStorage\tempImage.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(Uri address, String fileName) --- End of inner exception stack trace ---
at ProcessImage.GetFileFromUrl(String imageFileUrl, String newFileName)
at uploadexceldata.UploadExcelData(String fileName)
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() != "")
Does anyone have any suggestions on how to fix this exception?
解决方案Try setting the access permissions to "Full control" for the .Net user from where you are reading/saving the files.
这篇关于ASP.NET信息:System.UnauthorizedAccessException - 访问路径被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!