首先,我清楚我正在使用带有 DefaultAppPool(集成 4.0)的 ASP.NET 4.5。我还为 DefaultAppPool 用户配置了匿名访问。我已授予对 DefaultAppPool 的所有访问权限。System.Security.Principal.WindowsIdentity.GetCurrent()
方法给我相同的用户。但是当以下行运行时,它给了我Access to the path 'XXXX' is denied.
例外。然后出于测试目的,我已将所有权利授予EveryOne
用户,但仍然出现相同的错误。这是代码行。注意桁架
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