我的應用程序使用ASP.NET和C#創建,在讀取文檔時使用臨時路徑存儲文檔,然後在刪除文檔後刪除它:訪問臨時文件夾時,ASP.NET未被授權訪問請求的資源
string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))), File.Delete);
謝謝任何幫助。 StockControl文檔是一個示例,可以從網絡上的多臺計算機導入。基於錯誤信息,它看起來像我的文件不被上傳並保存到臨時目錄...
調試時本地路徑(工程):
C:\Users\USER\Documents\Visual Studio 2013\Projects\WebApplication5\WebApplication5\temp
的應用程序成功部署。然而,當我附加文件,然後按「導入」,我會顯示一條錯誤消息: 訪問路徑'C:\ inetpub \ wwwroot \ StockControl \ temp \ Book1.xls'被拒絕。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\StockControl\temp\Book1.xls' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in File Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
做什麼錯誤消息說:添加到您的web.config –
Zilog
2014-11-06 15:34:26
錯誤說,訪問路徑被拒絕。它不可能比這更明顯:)確保您的應用程序池標識可以訪問應用程序的整個根文件夾。 – PoweredByOrange 2014-11-06 15:49:15