asp.net - 无法在不同应用程序池中的应用程序之间共享隔离存储文件

标签 asp.net iis-7.5 isolatedstorage

我在 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

最佳答案

看起来这是一个信任问题。

将访问隔离存储文件的程序集添加到 gac 后,它神奇地工作了,因为 gac 中的所有内容都自动设置了完全信任。

这对我有用,但对于其他解决方案来说可能并不总是可以选择这样做。如果是这种情况,请检查 .NET Framework caspol 实用程序。

希望这对某人有帮助!这对我来说是一个巨大的坑。

关于asp.net - 无法在不同应用程序池中的应用程序之间共享隔离存储文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15649947/

相关文章:

WCF安全,用户名密码无证书

windows-phone-7 - 如何将 DateTime 存储在 Windows Phone 的隔离存储中?

c# - 重命名 IsolatedStorage 中的文件

c# - 写入项目文件夹中的文件 - 不允许操作

c# - 相对路径,可在控制台应用程序和 ASP.NET Web 应用程序中使用

c# - 使用 open id connect server 在 asp.net core 中检索声明

javascript - 400 错误请求 - jquery WCF ajax 调用

c# - 通过 Azure AD ADAL 的 ASP.NET MVC 用户身份验证

c# - 从同一服务器上的 MVC 调用 WCF 服务时出现 SocketException

http - Unity WWW Class Method Post 在 IIS7.5 上使用 Coldfusion 9 上传文件时出现错误