2011-07-13 47 views
4

我有一個很大的web應用程序。這個Web應用程序的一小部分使用OpenXML庫(用C#編寫)生成XLSX文件。OpenXML,IsolatedStorage,NETWORK SERVICE和Windows Server 2008

我碰到的這個帖子描述的問題:IsolatedStorage Access Denied

然而,說明也有適用於Windows Server 2003,並在2008年用戶目錄層次結構是不同的。

我試圖在這些位置創建IsolatedStorage目錄(然後給NETWORK SERVICE權限的話):

C:\用戶\ DEFAULT \應用程序數據\本地\ IsolatedStorage C:\用戶\ DEFAULT \ AppData \ Roaming \ IsolatedStorage

那些沒有工作。我試圖找到適用於IsolatedStorage目錄的位置在Windows Server 2008上(通常使用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() 
+0

找到了此:http://msdn.microsoft.com/en-us/library/3ak841sy.aspx。 如果Vista的信息也適用於Windows Server 2008,則該位置應該是: C:\用戶\ DEFAULT \應用程序數據\本地\微軟\ IsolatedStorage或 C:\用戶\ DEFAULT \應用程序數據\漫遊\微軟\ IsolatedStorage。 因此,我創建了這兩個目錄,並賦予NETWORK SERVICE對它們的完全控制權,並且創建.XLSX文件仍然失敗。 –

+0

我無法嘗試創建目錄,並在鏈接到上面的博客文章中重新創建解決方案。看起來我的選擇是讓文件變小,或者看看是否有辦法強制OpenXML以不切換到IsolatedStorage的方式實例化歸檔庫。 –

+0

沒有找到一種方法來防止OpenXML不使用IsolatedStorage。我能夠使用ILSpy查看選擇是否使用它,但我看不到任何明顯的方式來更改它用於在MemoryStream和IsolatedStorage之間切換的highwatermark var。我確實發現NETWORK SERVICE帳戶在Win Server 2008上使用的特定配置文件 - 它是C:\ Windows \ ServiceProfiles \ NetworkService,但即使創建IsolatedStorage文件夾也沒有任何幫助。 –

回答

4

在我的研究,我碰到這個博客帖子跌跌撞撞,以及:http://www.kevinrohrbaugh.com/blog/tag/openxml

我解僱它在第一,因爲這是不可能的,讓我有我的應用程序模擬其他用戶,由於它的方式與我無法控制的另一個Web應用程序進行交互。

不過,我開始思考,也許這我擺脫了在ProfileList文件網絡服務的註冊表項中,我能得到同樣的結果。因此,我將HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList \ S-1-5-20更名爲HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ ProfileList \ S-1-5-20-備份並重新運行我的Excel導出並正常工作。據我所知,做這件事沒有任何負面結果。

0

[我會加入這個作爲一個評論,但我沒有權限...]

我希望這可以幫助別人......

我在IIS快遞運行的應用程序作爲Windows Server 2008 R2上的網絡服務。從調用IsolatedStorageFile.GetMachineStoreForDomain()調用返回的獨立存儲區位於:c:\ ProgramData \ IsolatedStorage