访问路径' '当我将文本文件复制到服务器上的另一个文件夹时,被拒绝

时间:2016-05-03 07:46:01

标签: vb.net

我尝试从服务器复制文件,然后将其放到本地空间"我"在工作中,如果我尝试在localhost工作,但当我尝试在服务器上从标题获取错误:

My.Computer.FileSystem.CopyFile(
        Server.MapPath("../../TempDownloads/Template_BOM.xlsx"),
        "\\art-fs02\07_ART_ECO\12_Samples\03_Samples_order\999_MoraruVladutBOM_Test\SO-300.xlsx")

我的错误:

Access to the path '\\art-fs02\07_ART_ECO\12_Samples\03_Samples_order\999_MoraruVladutBOM_Test' 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. 

Exception Details: System.UnauthorizedAccessException: Access to the path '\\art-fs02\07_ART_ECO\12_Samples\03_Samples_order\999_MoraruVladutBOM_Test' 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. 

Exception Details: System.UnauthorizedAccessException: Access to the path '\\art-fs02\07_ART_ECO\12_Samples\03_Samples_order\999_MoraruVladutBOM_Test' 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 `<identity impersonate="true"/>`, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 

7 个答案:

答案 0 :(得分:2)

似乎您没有所需权限或无法访问文件共享。首先,您应该尝试访问共享文件夹,以查看该文件夹是否存在于共享中。只需将文件夹路径粘贴到新的Windows资源管理器地址栏即可。

然后,您需要向该文件夹/共享授予写入或其他适当的权限。为此,您需要将应用程序池用户添加到文件夹安全性和共享安全性选项卡。

答案 1 :(得分:2)

出于安全原因,您应该仅允许授权用户进行文件操作。为此:
1.将包含文件操作的页面放在单独的文件夹(站点内部)中,例如“securefolder” 2.将位置部分添加到web.config(内部配置部分)

  <location path="securefolder">
    <system.web>
      <authorization>
        <allow roles="Administrators" />
        <deny users="*" />
      </authorization>
      <identity impersonate="true" />
    </system.web>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
  </location>
    在IIS控制台中
  1. 转到身份验证并仅启用“基本”和“匿名”身份验证。匿名用户可以看到除安全文件夹之外的整个网站。当您进入安全文件夹时,将要求您提供UN / PWD。它在我的系统上运行良好。

答案 2 :(得分:1)

您的应用程序池使用什么标识(默认情况下是ApplicationPoolIdentity,本地帐户)?该用户通常需要访问授予您尝试访问的任何网络资源,因此最简单的方法是将域帐户设置为应用程序池用户,然后授予该域用户访问网络共享的权限。

答案 3 :(得分:1)

错误是:

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

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

我的解决方案是将以下内容添加到web.config:

<system.web>
 <identity impersonate="true" userName="administrator" password="xxxxxxx" />      
</system.web

答案 4 :(得分:1)

您可能需要授予IIS_USERS对目标文件或文件夹的访问权限: 在资源管理器中,右键单击目标文件或文件夹, 选择“属性 - &gt;安全性标签 - &gt;按钮编辑 - &gt;按钮添加 - &gt;高级 - &gt;立即查找。

向下滚动并选择IIS_IUSRS。这应该授予IIS_USERS访问目标文件的权限。

答案 5 :(得分:1)

您的Web应用程序将尝试使用ASPNET用户访问网络路径,因此您可以使用三个解决方案中的一个解决方案,而第四个解决方案从未尝试但可能有效(我认为):

  • 模仿:使用任何拥有权限的用户......根据我的理解,由于多用户,这不是一个选项。

  • 您希望每个用户都使用自己的凭据,您是否拥有访问此页面的每个用户的Windows用户名和密码?如果是,第二个解决方案是使用这些凭证访问网络路径:

查看this

  • 第三种解决方案是为{MACHINE} \ ASPNET用户授予访问此路径的权限。

  • 将网络路径映射为Windows中的驱动器(完全猜测但值得尝试):)

祝你好运

答案 6 :(得分:0)

尝试这可能会解决您的问题

System.IO.Directory.CreateDirectory(DirectoryPath);
System.Security.AccessControl.DirectorySecurity sec = Directory.GetAccessControl(DirectoryPath);
// Using this instead of the "Everyone" string means we work on non-English systems.
var everyone = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(everyone, System.Security.AccessControl.FileSystemRights.Modify | System.Security.AccessControl.FileSystemRights.Synchronize, System.Security.AccessControl.InheritanceFlags.ContainerInherit | System.Security.AccessControl.InheritanceFlags.ObjectInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow));
Directory.SetAccessControl(DirectoryPath, sec);