8

我在我的 ASP.NET MVC 3 应用程序中使用 EPPlus 2.8.0.2 库来生成 excel 文件。此应用程序在 Windows Server 2003 R2 上的 IIS 6 上运行。

违规行是这样的:

xlsdoc.GetAsByteArray

xlsdoc 是正确加载的 ExcelPackage 对象。

生成小输出很好,但生成大输出会产生错误:

System.IO.IsolatedStorage.IsolatedStorageException: Initialization failed.
   at System.IO.IsolatedStorage.IsolatedStorageFile.Init(IsolatedStorageScope scope)
   at System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
   at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder.GetCurrentStore()
   at MS.Internal.IO.Packaging.PackagingUtilities.ReliableIsolatedStorageFileFolder..ctor()
   at MS.Internal.IO.Packaging.PackagingUtilities.GetDefaultIsolatedStorageFile()
   at MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName)
   at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary()
   at MS.Internal.IO.Packaging.SparseMemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.Write(String value)
   at System.IO.TextWriter.Write(String format, Object arg0)
   at OfficeOpenXml.ExcelWorksheet.UpdateRowCellData(StreamWriter sw)
   at OfficeOpenXml.ExcelWorksheet.SaveXml()
   at OfficeOpenXml.ExcelWorksheet.Save()
   at OfficeOpenXml.ExcelWorkbook.Save()
   at OfficeOpenXml.ExcelPackage.GetAsByteArray(Boolean save)
   at OfficeOpenXml.ExcelPackage.GetAsByteArray()
   at ReportCenterLib.ReportGenerator.GenerateStream(DataTable result, String reporttitle, String inputparmstr, String conndescs, String username, String outputtype, String templatefile) in D:\PROJECTS\reportcentermvc\sources\ReportCenterLib\ReportGenerator.vb:line 450
   at ReportCenterMVC.ReportCenterMVC.ReportController.Generate(Int64 id, IList`1 conns, IDictionary`2 parms, String outputtype) in D:\PROJECTS\reportcentermvc\sources\ReportCenterMVC\Controllers\ReportController.vb:line 218

我怀疑EPPlus 尝试使用IsolatedStorage 创建临时文件,但没有写入IsolatedStorage 的权限。我已将应用程序池标识更改为“本地系统”,错误消失了。

使用“网络服务”身份时如何避免此错误?

4

2 回答 2

8

有人在博客上写过这个。他得到的错误(拒绝访问)与我得到的错误不同,但他的解决方案对我有用:

  • 在服务器上创建一个文件夹C:\Documents and Settings\Default User\Local Settings\Application Data\IsolatedStorage
  • 向每个人授予对该文件夹的写入权限
于 2011-10-11T02:56:26.917 回答
0

在这里讨论:http: //openxmldeveloper.org/

提炼:

在以下路径“C:\Documents and Settings\Default User\Local Settings\Application Data”创建名为 IsolatedStorage 的文件夹,并授予 IIS_WPG 修改和写入权限。这解决了windows server 2003上的问题

于 2014-08-05T21:35:30.970 回答