【发布时间】:2011-10-04 11:38:12
【问题描述】:
我有一个大型网络应用程序。这个 Web 应用程序的一小部分使用 OpenXML 库(用 C# 编写)生成 XLSX 文件。
我遇到了这篇文章中描述的问题:IsolatedStorage Access Denied
但是,这里的说明是针对 Windows Server 2003 的,而 2008 中的用户目录层次结构有所不同。
我尝试在这些位置创建 IsolatedStorage 目录(然后授予 NETWORK SERVICE 权限):
C:\Users\Default\AppData\Local\IsolatedStorage C:\Users\Default\AppData\Roaming\IsolatedStorage
那些没有用。我试图在 Windows Server 2008 上(通常使用 Google,特别是这里)找到 IsolatedStorage 目录的适当位置,但没有成功。
谁能告诉我应该在哪里创建该目录(或者,建议一些其他解决方案,强制 OpenXML 指示存档库不使用 IsolatedStorage 来创建电子表格)?
编辑 - 2011 年 7 月 14 日 - 添加异常消息和堆栈跟踪,以便希望帮助其他人找到它。
Exception: System.ApplicationException
Message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Source: mscorlib
at System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetRootDir(IsolatedStorageScope scope)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope scope)
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..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.EnsureIsolatedStoreStream()
at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary()
at MS.Internal.IO.Zip.ZipIOFileItemStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Compression.DeflateStream.InternalWrite(Byte[] array, Int32 offset, Int32 count, Boolean isAsync)
at System.IO.Compression.DeflateStream.Write(Byte[] array, 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.Xml.XmlUtf8RawTextWriter.FlushBuffer()
at System.Xml.XmlUtf8RawTextWriter.WriteAttributeTextBlock(Char* pSrc, Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)
at DocumentFormat.OpenXml.OpenXmlElement.WriteAttributesTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w)
at DocumentFormat.OpenXml.OpenXmlPartRootElement.WriteTo(XmlWriter xmlWriter)
at DocumentFormat.OpenXml.OpenXmlPartRootElement.SaveToPart(OpenXmlPart openXmlPart)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContents()
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(Boolean disposing)
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Close()
【问题讨论】:
-
找到这个:msdn.microsoft.com/en-us/library/3ak841sy.aspx。如果 Vista 的信息也适用于 Windows Server 2008,则位置应为:C:\Users\Default\AppData\Local\Microsoft\IsolatedStorage 或 C:\Users\Default\AppData\Roaming\Microsoft\IsolatedStorage。因此,我创建了这两个目录并让 NETWORK SERVICE 完全控制它们,但 .XLSX 文件的创建仍然失败。
-
在我上面链接到的博客文章中尝试创建目录并重新创建解决方案时,我没有任何进展。看起来我的选择是要么使文件更小,要么看看是否有办法强制 OpenXML 以不切换到独立存储的方式实例化存档库。
-
没有运气找到阻止 OpenXML 不使用独立存储的方法。我能够使用 ILSpy 来查看它在哪里选择是否使用它,但我看不到任何明显的方法来更改它用于在 MemoryStream 和 IsolatedStorage 之间切换的高水位线变量。我确实找到了 NETWORK SERVICE 帐户在 Win Server 2008 上使用的特定配置文件 - 它是 C:\Windows\ServiceProfiles\NetworkService,但即使在那里创建独立存储文件夹也无济于事。
-
您确定遇到了同样的问题吗?在 Windows 2008 上,应用程序池默认使用“应用程序池标识”帐户,该帐户在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList 中没有条目,因此我们在 2008 年根本没有出现问题。如果您在 Windows 2008 上使用网络服务也许您可以恢复到默认的“应用程序池标识”设置。
-
我们正在为这个特定的应用程序使用网络服务。老实说,我不知道究竟是为什么,但我的理解是,在事情成立时做出选择是有充分理由的。
标签: c# windows-server-2008 openxml isolatedstorage