Share via


IsolatedStorageContainment 枚举

指定独立存储区所允许的用途。

**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration IsolatedStorageContainment
用法
Dim instance As IsolatedStorageContainment
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum IsolatedStorageContainment
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class IsolatedStorageContainment
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum IsolatedStorageContainment
SerializableAttribute 
ComVisibleAttribute(true) 
public enum IsolatedStorageContainment

成员

  成员名称 说明
AdministerIsolatedStorageByUser 对用户存储区的无限制的管理能力。允许浏览和删除整个用户存储区,但除用户自己的域/程序集标识外,不允许进行读访问。 
ApplicationIsolationByMachine 存储首先按计算机隔离,然后按应用程序隔离。这为在任何域上下文中均可访问的应用程序提供了数据存储区。基于应用程序的数据隔离舱需要额外的信任,原因是数据隔离舱可能会在应用程序之间提供“隧道”,从而危及特定网站中应用程序的数据隔离。 
ApplicationIsolationByRoamingUser 存储首先按用户隔离,然后按应用程序证据隔离。当启用 Windows 用户数据漫游时,存储将漫游。这为在任何域上下文中均可访问的应用程序提供了数据存储区。基于应用程序的数据隔离舱需要额外的信任,原因是数据隔离舱可能会在应用程序之间提供“隧道”,从而危及特定网站中应用程序的数据隔离。 
ApplicationIsolationByUser 存储首先按用户隔离,然后按应用程序隔离。存储也被计算机隔离。这为在任何域上下文中均可访问的应用程序提供了数据存储区。基于应用程序的数据隔离舱需要额外的信任,原因是数据隔离舱可能会在应用程序之间提供“隧道”,从而危及特定网站中应用程序的数据隔离。 
AssemblyIsolationByMachine 存储首先按计算机隔离,然后按代码程序集隔离。这为在任何域上下文中都可访问的程序集提供了数据存储区。基于程序集的数据室需要额外的信任,因为它可能在应用程序之间提供“隧道”,该隧道会危及特定网站中应用程序的数据隔离。 
AssemblyIsolationByRoamingUser 存储首先按用户隔离,然后按程序集证据隔离。当启用 Windows 用户数据漫游时,存储将漫游。这为在任何域上下文中都可访问的程序集提供了数据存储区。基于程序集的数据室需要额外的信任,因为它可能在应用程序之间提供“隧道”,该隧道会危及特定网站中应用程序的数据隔离。 
AssemblyIsolationByUser 存储首先按用户隔离,然后按代码程序集隔离。存储也被计算机隔离。这为在任何域上下文中都可访问的程序集提供了数据存储区。基于程序集的数据室需要额外的信任,因为它可能在应用程序之间提供“隧道”,该隧道会危及特定网站中应用程序的数据隔离。 
DomainIsolationByMachine 存储首先按计算机隔离,然后按域和程序集隔离。只有在相同应用程序的上下文内并且仅在相同的计算机上运行时,才可访问数据。这在第三方程序集想要保留私有数据存储区时很有用。 
DomainIsolationByRoamingUser 存储首先按用户隔离,然后按域和程序集隔离。当启用 Windows 用户数据漫游时,存储将漫游。只有在相同应用程序的上下文内并且仅由相同用户运行时,才可访问数据。这在第三方程序集想要保留私有数据存储区时很有用。 
DomainIsolationByUser 存储首先按用户隔离,然后按域和程序集隔离。存储也被计算机隔离。只有在相同应用程序的上下文内并且仅由相同用户运行时,才可访问数据。这在第三方程序集想要保留私有数据存储区时很有用。 
None 不允许使用独立存储。 
UnrestrictedIsolatedStorage 允许在没有任何限制的情况下使用独立存储。代码对用户存储区的任何部分均有完全访问权限,而不管域或程序集的标识如何。独立存储的这种使用允许对独立存储数据存储区中的内容进行枚举。 

备注

独立存储区使用证据来确定应用程序或组件使用的唯一存储区域。程序集的标识唯一确定该程序集所使用的虚拟文件系统的根。因此,与许多应用程序和组件共享文件系统或注册表等公共资源不同,每个应用程序和组件都有固定分配给它的文件区域。

在分配独立存储区时使用四个基本的隔离范围:

  • User - 始终根据当前用户来确定代码的作用范围。当由不同用户运行时,同一程序集将接收不同的存储区。

  • Machine - 始终根据计算机来确定代码的作用范围。当同一程序集由不同用户在同一计算机上运行时,它将接收相同的存储区。

  • Assembly - 代码通过下列项以加密方式进行标识:强名称(例如 Microsoft.Office.* 或 Microsoft.Office.Word)、发行者(基于公钥)、URL(例如 https://www.fourthcoffee.com/process/grind.htm)、站点或区域。

  • Domain - 根据与应用程序域关联的证据标识代码。Web 应用程序标识是从站点的 URL、网页的 URL、站点或区域导出的。本地代码标识基于应用程序目录路径。

有关 URL、站点和区域的定义,请参见 UrlIdentityPermissionSiteIdentityPermissionZoneIdentityPermission

这些标识组合在一起,在这种情况下,将依次应用这些标识符,直到创建了所需的独立存储区为止。有效的组合是“用户 + 程序集和用户 + 程序集 + 域”。这种标识组合在许多不同的应用程序中很有用。

如果数据是按域、用户和程序集存储的,则该数据是私有的,因为只有该程序集内的代码可以访问该数据。数据存储区还按在其中运行的应用程序进行隔离,所以程序集不会通过向其他应用程序公开数据而造成潜在的安全漏洞。

对于适用于多个应用程序的用户数据,例如许可证信息或独立于应用程序的用户个人信息(姓名、身份验证凭据等),可以按程序集和用户进行隔离。

IsolatedStorageContainment 将公开一些标志,它们确定是否允许应用程序使用独立存储,并确定所允许的标识组合(如果允许使用独立存储)。它还确定是否允许应用程序在可随用户漫游的位置存储信息(必须配置“Windows 漫游用户配置文件”或“文件夹重定向”)。

示例

此示例演示如何通知 CLR 此程序集中的代码需要 IsolatedStoragePermission,还演示如何对独立存储进行读写。

using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;

// Notify the CLR to grant this assembly the IsolatedStorageFilePermission. 
// This allows the assembly to work with storage files that are isolated 
// by user and assembly.
[assembly: IsolatedStorageFilePermission(SecurityAction.RequestMinimum, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]

public sealed class App
{
    static void Main()
    {
        // Attempt to create a storage file that is isolated by user and assembly.
        // IsolatedStorageFilePermission granted to the attribute at the top of this file 
        // allows CLR to load this assembly and execution of this statement.
        using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly()))
        {
         
             // Write some data out to the isolated file.
             using (StreamWriter sw = new StreamWriter(s))
             {
                sw.Write("This is some test data.");
             }
        }

        // Attempt to open the file that was previously created.
        using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly()))
        {
             // Read the data from the file and display it.
             using (StreamReader sr = new StreamReader(s))
             {
                 Console.WriteLine(sr.ReadLine());
             }
        }
    }
}

// This code produces the following output.
//
//  Some test data.
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::IO::IsolatedStorage;
using namespace System::IO;

// Notify the CLR to grant this assembly the IsolatedStorage-
// FilePermission. This allows the assembly to work with storage
// files that are isolated by user and assembly.
[assembly: IsolatedStorageFilePermission(
    SecurityAction::RequestMinimum, UsageAllowed =
    IsolatedStorageContainment::AssemblyIsolationByUser)];
int main()
{
    try
    {
        // Attempt to create a storage file that is isolated by
        // user and assembly. IsolatedStorageFilePermission
        // granted to the attribute at the top of this file
        // allows CLR to load this assembly and execution of this
        // statement.
        Stream^ fileCreateStream = gcnew
            IsolatedStorageFileStream(
            "AssemblyData",
            FileMode::Create,
            IsolatedStorageFile::GetUserStoreForAssembly());

        StreamWriter^ streamWriter = gcnew StreamWriter(
            fileCreateStream);
        try
        {
            // Write some data out to the isolated file.

            streamWriter->Write("This is some test data.");
            streamWriter->Close();   
        }
        finally
        {
            delete fileCreateStream;
            delete streamWriter;
        } 
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }

    try
    {
        Stream^ fileOpenStream =
            gcnew IsolatedStorageFileStream(
            "AssemblyData",
            FileMode::Open,
            IsolatedStorageFile::GetUserStoreForAssembly());
        // Attempt to open the file that was previously created.

        StreamReader^ streamReader = gcnew StreamReader(
            fileOpenStream);
        try
        { 
            // Read the data from the file and display it.

            Console::WriteLine(streamReader->ReadLine());
            streamReader->Close();
        }
        finally
        {
            delete fileOpenStream;
            delete streamReader;
        }
    }
    catch (FileNotFoundException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}

// This code produces the following output.
//
//  This is some test data.

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

System.Security.Permissions 命名空间
IsolatedStoragePermission
IsolatedStoragePermissionAttribute
IsolatedStorageFilePermission
IsolatedStorageFilePermissionAttribute

其他资源

独立存储