我有一个 Web 客户端,它以 XML 的形式向我的 Web 服务器发送请求。Web 服务器创建一个(相当大的)文件并将其保存在缓存目录中,并通过响应流将其返回给 Web 客户端。这在我尝试的前几次运行良好,但突然停止工作并报告以下异常(用 XML 包装):
<error type="System.Security.SecurityException">
<message>Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</message>
<stack-trace><![CDATA[ at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at 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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at Ionic.Zip.SharedUtilities.CreateAndOpenUniqueTempFile(String dir, Stream& fs, String& filename)
at Ionic.Zip.ZipFile.get_WriteStream()
at Ionic.Zip.ZipFile.Save()
at Ionic.Zip.ZipFile.Save(String fileName)
at MyApplication.UpdateItemFiles.GetUpdateContent(XDocument a_xManifest, Stream[] a_arrExtraContent) in C:\Software\MyApplication\Alpha\Web Interface\UpdateItemFiles.aspx.cs:line 265
at MyApplication.UpdateItemFiles.Page_Load(Object sender, EventArgs e) in C:\Software\MyApplication\Alpha\Web Interface\UpdateItemFiles.aspx.cs:line 31]]></stack-trace>
</error>
我对代码访问安全性了解不多。我什至尝试将目录的完全控制权交给每个人。这不是问题,因为这是开发服务器而不是公共机器。我不明白为什么这会在前几次起作用,但现在停止工作。
我在 Windows 7 64 位上为服务器和客户端(它们是同一台机器)使用 Visual Studio 2008。我正在使用 IIS 7.0 和 .Net Framework 3.5。
美国东部时间 2010 年 12 月 13 日 16:05 编辑:
我收到此错误是因为我使用的是 Codeplex 的 DotNetZip 库。有没有办法将程序集添加到 IIS 或我的配置?