【问题标题】:Uploading files: Access to path denied上传文件:访问路径被拒绝
【发布时间】:2026-02-11 11:10:01
【问题描述】:

我已经让 IUSR 完全控制文件夹,但是当我上传文件时,它给了我这个错误: 拒绝访问路径“C:\inetpub\wwwroot\vivaweb\usr_up_img\Desert.jpg”。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\vivaweb\usr_up_img\Desert.jpg' 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) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, 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 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:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\vivaweb\usr_up_img\Desert.jpg' is denied.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7716783
   System.IO.File.Delete(String path) +7577512
   ASP.vivaweb_dwzupload_resizeaspnet_aspx.ResizeImage(String oldPathImage, String newPathImage, Int32 Width, Int32 Height, Int32 imgQuality, Boolean keep, Boolean isThumb) +217
   ASP.vivaweb_dwzupload_resizeaspnet_aspx.Page_Load(Object sender, EventArgs e) +379
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

【问题讨论】:

  • 你在使用源代码管理吗?

标签: asp.net


【解决方案1】:

很明显您的应用程序正在使用“ASP.NET”用户

所以给这个用户权限或者干脆给用户everyone

【讨论】:

  • 没有我的 godaddy windows plesk 服务器,当我在本地计算机上通过为“每个人”分配权限来执行此操作时,您无法在用户列表中找到“每个人”,但我没有不知道如何在 windows plesk 主机上进行操作
【解决方案2】:

在这篇文章中有一些未解决的问题,我必须做出一些假设。首先,我不知道您是如何部署站点的,因此不知道它使用的是什么身份。如果您直接通过 Visual Studio 运行它,根据您的版本,它应该使用"ApplicationPoolIdenity" or "NetworkService"

如果您通过 IIS 运行您的网站,您可以轻松解决这个问题(如果您愿意,可以更改它)。只需打开 IIS 实例下的应用程序池,您应该会在“身份”列中看到它们。

之后,您需要确保授予与您网站所用身份相同的权限。获取用于存放站点的根文件夹并为其授予适当的权限。右键单击该文件夹并转到属性 -> 安全 -> 编辑。添加您的网站正在使用的身份,您应该完成。

最后一点,如果您在本地/调试环境中,您实际上可能希望在 web.config 文件中打开调试配置设置。它将提供更多信息来解决您的问题。

【讨论】:

  • 让它在本地工作对我来说真的很简单,只需让每个人都完全控制它就可以了。现在的问题是如何使它在线工作,因为在托管服务器上的给定用户中没有“每个人”。不知道能不能通过web.config实现
  • 您是否尝试为其中任何一个实体添加权限?无论如何,您可能不希望每个人都对您的文件拥有完全权限。默认的 IIS 帐户是“LocalService”“LocalSystem”“NetworkService”和“ApplicationPoolIdentity”。先试试那些。我还通过快速的谷歌搜索(如何设置 plesk 权限)找到了这一点。不确定是否是您需要的:support.godaddy.com/help/article/6481/…
  • 感谢您的热心帮助,但在 godaddy plesk 服务器上没有网络服务和 Applicationpoolidentity 在那里找到
最近更新 更多