ExtractToFile抛出访问被拒绝错误?

时间:2013-02-10 06:31:59

标签: c# security iis

首先,我清楚我使用ASP.NET 4.5和DefaultAppPool(集成4.0)。我还配置了对DefaultAppPool用户的匿名访问。我已经授予了对DefaultAppPool的所有访问权限。 System.Security.Principal.WindowsIdentity.GetCurrent()方法为我提供了相同的用户。但是当以下行运行时,它会给我Access to the path 'XXXX' is denied.例外。然后出于测试目的,我已授予EveryOne用户所有权利,但仍然收到相同的错误。这是代码行。注意trus

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

这是StackTrace,

[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

1 个答案:

答案 0 :(得分:12)

在这种情况下,.NET框架给了我错误的异常。问题是,我只是传递位置(没有文件名的文件夹位置)。因此,在包含完整路径之后,这可行。