我在默认网站下的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