c# - 访问临时文件夹时,ASP.NET 无权访问请求的资源

标签 c# asp.net iis

我使用 ASP.NET 和 C# 创建的应用程序在读取文档时使用临时路径存储文档,然后在以下时间后将其删除:

string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));

Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))), File.Delete);

谢谢你的帮助。 StockControl 文档是一个示例,可以从网络上的多台计算机导入。根据错误消息,我的文件似乎没有上传并保存到临时目录中...

调试时的本地路径(WORKS):

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.

最佳答案

我也有同样的问题。

进行了以下更改以解决此问题。

(1) 我进入了 wwwroot 文件夹。右键单击和安全选项卡。提供IISUSER设置对wwwroot文件夹的读写权限。

(2)将application pool改为separate pool,identity设置为Application pool Identity。

关于c# - 访问临时文件夹时,ASP.NET 无权访问请求的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26783183/

相关文章:

C# 按自定义要求订购 IEnumerable

c# - 处理具有重复逻辑的冗余代码的最佳方法?

c# - HMM 使用 Accord.Net 进行手势识别

asp.net - 两个 Azure VM 之间的延迟

asp.net - HTML Help Workshop 仍然是与应用程序一起使用的可行选择吗?

iis - HTTP 错误 403.14 - 禁止 asp.net 5 和 MVC 6 iis10

c# - 将对象 [,] 转换为字符串 [,]?

asp.net - 存储过程中的范围标识

.net - 使用 Microsoft.Web.Administration 中的 ServerManager 类时出现 COM 异常

asp.net - 无法访问 Azure Web App 上的 SQLite DB