1

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 アセンブリに同じ権限を付与するにはどうすればよいですか?

4

1 に答える 1

1

それを自分で考え出した:

アプリケーション プールで、Load User プロファイルを true に設定しました....問題は解決しました。アセンブリはまったくユーザーなしで実行されていたと思います (全員、匿名、誰もいない)

于 2012-04-26T21:11:11.257 に答える