访问临时文件夹时,ASP.NET无权访问所请求的资源 [英] ASP.NET is not authorized to access the requested resource when accessing temp folder

查看:1290
本文介绍了访问临时文件夹时,ASP.NET无权访问所请求的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

my application that I have created using ASP.NET and C# uses a temporary path to store a document whilst it is read, and then deletes it after:

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

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

谢谢你的任何帮助。 StockControl文档是一个示例,可以从网络上的多台计算机导入。基于错误消息看起来我的文件没有被上传并保存到临时目录...

Thankyou for any help. The StockControl document is an example and could be imported from multiple computers on a network. based on the error message it looks like my file is not being uploaded and saved into the temp directory...

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

local path when debugging (WORKS):

C:\Users\USER\Documents\Visual Studio 2013\Projects\WebApplication5\WebApplication5\temp

应用程序已成功部署但是当我附加文件并按导入时,我会显示错误消息:
访问路径'C:\inetpub \wwwroot \StockControl\temp \ Book1.xls'被拒绝。

the application is successfully deployed however when i attach the file and press "Import", i get displayed an error message: Access to the path 'C:\inetpub\wwwroot\StockControl\temp\Book1.xls' is denied.

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. 




异常详细信息:System.UnauthorizedAccessException:访问
路径'C:\inetpub \ www.root \StockControl\temp\Book1.xls'被拒绝。

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\StockControl\temp\Book1.xls' is denied.

ASP.NET无权访问所请求的资源。考虑
将资源的访问权限授予ASP.NET请求
标识。 ASP.NET具有基本进程标识(通常是IIS 5上的
{MACHINE} \ ASPNET或IIS 6和IIS 7上的网络服务,以及在IIS 7.5上配置的应用程序池标识
)如果
该申请不是假冒的。如果应用程序为
模拟通过,则匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的
请求用户的身份将为

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.

要授予对文件的ASP.NET访问权限,请右键单击File
Explorer中的文件,选择属性,然后选择安全选项卡。单击添加
以添加适当的用户或组。突出显示ASP.NET帐户,
并选中所需访问的框。

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.

源错误:

在执行
当前Web请求期间生成了未处理的异常。有关
的来源和位置的信息可以使用下面的异常堆栈跟踪来识别异常。

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.


推荐答案

解决我的问题的一个非常简单的解决方案,在IIS中我必须右键单击Application Pools并将.NET Framework V4设置为Integrated而不是classic /

a really simple fix to solve my issue, in IIS I had to right click on Application Pools and set .NET Framework V4 to Integrated rather than classic/

另一个解决方案是将正在访问的特定文件夹设置为对需要它的用户进行读/写,这可以由唯一用户或组织内的一组用户完成

Another solution was to set the specific folder that was being accessed to read/write to the users that required it, this can be done by unique users or within an organization, a group of users

这篇关于访问临时文件夹时,ASP.NET无权访问所请求的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆