2013-02-10 291 views
5

首先,我清楚我正在使用DefaultAppPool(集成4.0)的ASP.NET 4.5。我還配置了對DefaultAppPool用戶的匿名訪問。我已授予對DefaultAppPool的全部訪問權限。 System.Security.Principal.WindowsIdentity.GetCurrent()方法給我同一個用戶。但是,當下面的行運行它給我Access to the path 'XXXX' is denied.異常。然後出於測試目的,我已授予EveryOne用戶的所有權利,但仍然收到相同的錯誤。這是一行代碼。注意TRUSExtractToFile拋出訪問被拒絕錯誤?

 using (ZipArchive archive = new ZipArchive(zipStream)) 
     { 
      foreach (ZipArchiveEntry file in archive.Entries) 
      { 
       file.ExtractToFile(location,true); 
      } 
     } 

這裏是堆棧跟蹤,

[UnauthorizedAccessException: Access to the path 'XXX' is denied.] 
    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10793558 
    System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1352 
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +65 
    System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite) +96 
    XX.XX.XX.ExtractZipFile(Stream zipStream, String location) in XX.cs:44 
    XX.XX.XX.XX.XX.XX.ExtractZipFile(Stream zipStream, String location) in XXX.cs:17 

enter image description here

+0

DefaultAppPool用戶是否有權訪問(讀取/寫入權限)有問題的路徑? – Tim 2013-02-10 06:50:06

+0

@Tim,是完全控制。此外,我已經完全控制每個人的用戶。 – user960567 2013-02-10 06:52:22

+0

DefaultAppPool用戶是否對路徑中的所有文件夾執行/遍歷訪問? – 2013-02-10 06:59:14

回答

10

.NET在這種情況下,讓我錯了異常框架。問題是,我只是通過位置(沒有文件名的文件夾位置)。所以在包含完整路徑之後,這是有效的。