简体   繁体   中英

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:

 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. 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).

I use a helper class for this purpose: http://pastebin.com/HQWT7yFX (can't find original author, so this is my slightly modified version)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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