我在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的权限。我已将应用程序池标识更改为“本地系统”,并且错误消失了。
使用“网络服务”身份时如何避免此错误?
最佳答案
有人blogged about this。他遇到的错误(访问被拒绝)与我遇到的错误不同,但是他的解决方案对我有用:
C:\Documents and Settings\Default User\Local Settings\Application Data\IsolatedStorage
文件夹关于asp.net-mvc-3 - 初始化在IsolatedStorage上失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7711319/