我在默认网站下的 IIS 中有各种 Web 应用程序(包含 WCF 服务)。只要它们都在同一个应用程序池中运行,它们就可以访问共享的隔离存储文件没有问题。
但是,一旦我将它们移动到不同的应用程序池,当一个人尝试访问另一个人创建的文件时,我会得到“System.IO.IsolatedStorage.IsolatedStorageException: Unable to create mutex”。它们都在 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