首先,我清楚我使用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
答案 0 :(得分:12)