我在默認網站下的IIS中有各種Web應用程序(包含WCF服務)。只要它們都在同一個應用程序池中運行,它們就可以訪問共享的獨立存儲文件,而不會造成任何問題。無法在不同應用程序池中的應用程序之間共享獨立的存儲文件
但是,一旦我將它們移動到不同的應用程序池,當嘗試訪問由另一個應用程序創建的文件時,會出現「System.IO.IsolatedStorage.IsolatedStorageException:無法創建互斥體」。它們都在NetworkService用戶下運行。我嘗試了GetUserStoreForAssembly和GetMachineStoreForAssembly,所有結果都一樣。任何想法爲什麼他們不能使用共享文件?
我一定要關閉流,甚至處理它,以防止一個人抓住它,但我正在運行一個簡單的測試,其中一個服務寫入它,然後另一個服務器嘗試從後面讀取,並且總是失敗。
此外,我正在從已簽署的程序集訪問隔離存儲。
有沒有人有任何想法?
下面是代碼:
Private Sub LoadData()
Dim filename = FullFilePath(_fileName)
Dim isoStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
' Tried GetMachineStoreForAssembly, same failure
isoStorage.CreateDirectory(ROOT_DIRECTORY)
If (isoStorage.GetFileNames(filename).Length = 0) Then
Return
End If
Dim stream As Stream = New IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, isoStorage)
If stream IsNot Nothing Then
Try
Dim formatter As IFormatter = New BinaryFormatter()
Dim appData As Hashtable = DirectCast(formatter.Deserialize(stream), Hashtable)
Dim enumerator As IDictionaryEnumerator = appData.GetEnumerator()
While enumerator.MoveNext()
Me(enumerator.Key) = enumerator.Value
End While
Finally
stream.Close()
stream.Dispose()
stream = Nothing
End Try
End If
End Sub
Public Sub Save()
Dim filename = FullFilePath(_fileName)
' Open the stream from the IsolatedStorage.
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
' Tried GetMachineStoreForAssembly, same failure
Dim stream As Stream = New IsolatedStorageFileStream(filename, FileMode.Create, isoFile)
If stream IsNot Nothing Then
Try
Dim formatter As IFormatter = New BinaryFormatter()
formatter.Serialize(stream, DirectCast(Me, Hashtable))
Finally
stream.Close()
stream.Dispose()
stream = Nothing
End Try
End If
End Sub