简体   繁体   English

如何解决“拒绝访问路径”错误?

[英]How to fix “Access to the path is denied” error?

I have a folder and I want to some process in this folder like unzip and read a file. 我有一个文件夹,我想在该文件夹中进行一些处理,例如解压缩并读取文件。 It's perfect this part but I have an error like that when the try open the folder on asp.net: 这部分很完美,但是尝试打开asp.net上的文件夹时出现类似错误:

 Error: System.UnauthorizedAccessException: Access to the path
    \\101.101.101.126\d$\abc\abc\abc' is denied. 
         at System.IO.__Error.WinIOError(Int32 errorCode,
         String maybeFullPath) at System.IO.Directory.InternalGetFileDirectoryNames(String path, String
     userPathOriginal, String searchPattern, Boolean includeFiles, 
         Boolean includeDirs, SearchOption searchOption) at 
         System.IO.Directory.GetFiles(String path, 
         String searchPattern, SearchOption searchOption) at GetEmailReport.GetEmailCampaignDeliveryStatusReportViaFtp() in
          c:\abc\abc\abc.cs:line 120

I changed folder permission for ISS user ,Asp.Net and others but I have some err. 我更改了ISS用户,Asp.Net和其他用户的文件夹权限,但是我有些错误。 How to fix this error? 如何解决这个错误?

The user, whose account is used to run your application, must have access to that path 使用其帐户运行您的应用程序的用户必须有权访问该路径

There are 2 ways to achieve this: 有两种方法可以实现此目的:

  1. Configure a special application pool for your application, that will run under a user that has necessary permissions (can access admin shares on remote server). 为您的应用程序配置一个特殊的应用程序池,该池将在具有必要权限(可以访问远程服务器上的管理员共享)的用户下运行。 So your entire application will run under that account and have all its permissions. 因此,您的整个应用程序将在该帐户下运行并拥有所有权限。

  2. Using impersonation to execute parts of your code under another account. 使用模拟在另一个帐户下执行部分代码。 This doesn't require any IIS configuration and is more secure and flexible than first way (for example? you can impersonate several accounts in a single application). 这不需要任何IIS配置,并且比第一种方法更安全和灵活(例如,您可以在单个应用程序中模拟多个帐户)。

I use a helper class for this purpose: http://pastebin.com/HQWT7yFX (can't find original author, so this is my slightly modified version) 为此,我使用了一个帮助器类: http : //pastebin.com/HQWT7yFX (找不到原始作者,所以这是我稍加修改的版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM