C# OpenXML、隔离存储、网络服务和Windows Server 2008

C# OpenXML、隔离存储、网络服务和Windows Server 2008,c#,windows-server-2008,openxml,isolatedstorage,C#,Windows Server 2008,Openxml,Isolatedstorage,我有一个大型web应用程序。这个web应用程序的一小部分使用OpenXML库(用C#编写)生成XLSX文件 我遇到了这篇文章中描述的问题: 但是,Windows Server 2003的说明与2008中的用户目录层次结构不同 我已尝试在这些位置创建IsolatedStorage目录(然后为其授予网络服务权限): C:\Users\Default\AppData\Local\IsolatedStorage C:\Users\Default\AppData\Roaming\IsolatedStora

我有一个大型web应用程序。这个web应用程序的一小部分使用OpenXML库(用C#编写)生成XLSX文件

我遇到了这篇文章中描述的问题:

但是,Windows Server 2003的说明与2008中的用户目录层次结构不同

我已尝试在这些位置创建IsolatedStorage目录(然后为其授予网络服务权限):

C:\Users\Default\AppData\Local\IsolatedStorage C:\Users\Default\AppData\Roaming\IsolatedStorage

这些都不起作用。我试图在Windows Server 2008上找到IsolatedStorage目录的适当位置(通常使用Google,特别是在这里),但没有成功

有人能告诉我应该在哪里创建该目录吗(或者,建议一些其他解决方案,强制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()

在我的研究过程中,我也偶然发现了这篇博文:

我一开始就拒绝了它,因为我不可能让我的应用程序模拟另一个用户,因为它与另一个我无法控制的web应用程序交互的方式

然而,我开始思考,如果我在ProfileList中去掉了网络服务的注册表项,我可能会得到同样的结果


因此,我将HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20重命名为HKEY\U LOCAL\U MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20-backup,并重新运行Excel导出,它工作正常。据我所知,我没有因为这样做而产生任何负面结果。

[我本来会添加此作为评论,但我没有权限…]

我希望这能帮助其他人


我有一个应用程序在Windows Server 2008 R2的IIS Express中作为网络服务运行。调用IsolatedStorageFile.GetMachineStoreForDomain()返回的独立存储存储位于:c:\ProgramData\IsolatedStorage

找到以下位置:。如果Vista的信息也适用于Windows Server 2008,则位置应为:C:\Users\Default\AppData\Local\Microsoft\IsolatedStorage或C:\Users\Default\AppData\Roaming\Microsoft\IsolatedStorage。因此,我创建了这两个目录,并让网络服务完全控制它们,而.XLSX文件的创建仍然失败。在我上面链接的博文中尝试创建目录并重新创建解决方案,我没有任何进展。看起来我的选择是要么缩小文件,要么看看是否有办法强制OpenXML实例化存档库,使其不会切换到IsolatedStorage。没有办法阻止OpenXML不使用IsolatedStorage。我可以使用ILSpy查看它在哪里选择是否使用它,但我看不到任何明显的方法来更改它用于在MemoryStream和IsolatedStorage之间切换的highwatermark var。我确实找到了网络服务帐户在Win Server 2008上使用的特定配置文件-它是C:\Windows\ServiceProfiles\NetworkService,但即使在那里创建IsolatedStorage文件夹也没有帮助。您确定看到了相同的问题吗?在windows 2008上,应用程序池默认使用“应用程序池标识”帐户,该帐户在HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\windows NT\CurrentVersion\ProfileList中没有条目,因此我们在2008年完全没有出现此问题。如果您在windows 2008上使用网络服务,可能您可以还原为默认的“应用程序池标识”设置。我们正在为此特定应用程序使用网络服务。老实说,我不知道确切的原因,但我的理解是,有一个很好的理由,选择是在事情建立的时候。