DotNetZip FileIOPermission - 虽然我有权利,但无法将文件添加到zip中

时间:2012-04-26 14:12:08

标签: asp.net file-permissions dotnetzip

我完全无法通过dotnetzip将文件添加到.zip文件

我可以:

using (ZipFile zip = new ZipFile())
      {
zip.AddEntry("test.txt", DateTime.Now.ToString());
zip.Save(Response.OutputStream);
}

这已正确完成并生成一个可供下载的zip文件,可以使用

中的文本文件进行操作

问题:尝试添加这样的文件:

 zip.AddFile(Server.MapPath("/Files/test.txt"), "Files");

总是会产生这样的结果:

[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +61
   System.IO.File.GetLastWriteTimeUtc(String path) +114
   System.IO.File.GetLastWriteTime(String path) +24
   Ionic.Zip.ZipEntry.Create(String nameInArchive, ZipEntrySource source, Object arg1, Object arg2) in c:\DotNetZip\Zip\ZipEntry.cs:2405
   Ionic.Zip.ZipEntry.CreateFromFile(String filename, String nameInArchive) in c:\DotNetZip\Zip\ZipEntry.cs:2313
   Ionic.Zip.ZipFile.AddFile(String fileName, String directoryPathInArchive) in c:\DotNetZip\Zip\ZipFile.AddUpdate.cs:406
   Ionic.Zip.ZipFile.AddFile(String fileName) in c:\DotNetZip\Zip\ZipFile.AddUpdate.cs:296
   MultiFileDownloader.WebForm1.Button1_Click(Object sender, EventArgs e) in D:\WORK\dynamicweb\StandardModules\MultiFileDownloader\Source\MultiFileDownloader\WebForm1.aspx.cs:54
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
   System.Web.UI.Page.ProcessRequest() +80
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.webform1_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\ade7bc1a\c2b11481\App_Web_txhzteca.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

注意:我的代码可以毫无问题地读取/创建文件。 IIS用户(以及所有人)都拥有相关文件的完全权限。 IIS 7.5,win2008r2

如何授予DotNetZip程序集相同的权利?

1 个答案:

答案 0 :(得分:1)

想出我自己:

在应用程序池上,我将Load User配置文件设置为true ....问题已解决。猜测组件在没有任何用户的情况下运行(不是每个人,不是异常,不是没有人)