首先,我想强调我使用的是 ASP.NET 4.5 版本,DefaultAppPool (integrated 4.0)。我已经将匿名访问权限配置给了 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);
}
}
以下是 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