gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:06:16 26 4
gpt4 key购买 nike

我使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com