IsolatedStorageContainment 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
Code Access Security is not supported or honored by the runtime.
指定独立存储区所允许的用途。
public enum class IsolatedStorageContainment
public enum IsolatedStorageContainment
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum IsolatedStorageContainment
[System.Serializable]
public enum IsolatedStorageContainment
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum IsolatedStorageContainment
type IsolatedStorageContainment =
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type IsolatedStorageContainment =
[<System.Serializable>]
type IsolatedStorageContainment =
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type IsolatedStorageContainment =
Public Enum IsolatedStorageContainment
- 继承
- 属性
字段
AdministerIsolatedStorageByUser | 112 | 对用户存储区的无限制的管理能力。 允许浏览和删除整个用户存储区,但除用户自己的域/程序集标识外,不允许进行读访问。 |
ApplicationIsolationByMachine | 69 | 存储首先按计算机隔离,然后按应用程序隔离。 这为在任何域上下文中均可访问的应用程序提供了数据存储区。 基于应用程序的数据隔离舱需要额外的信任,原因是数据隔离舱可能会在应用程序之间提供“隧道”,从而危及特定网站中应用程序的数据隔离。 |
ApplicationIsolationByRoamingUser | 101 | 存储首先按用户隔离,然后按应用程序证据隔离。 当启用 Windows 用户数据漫游时,存储将漫游。 这为在任何域上下文中均可访问的应用程序提供了数据存储区。 基于应用程序的数据隔离舱需要额外的信任,原因是数据隔离舱可能会在应用程序之间提供“隧道”,从而危及特定网站中应用程序的数据隔离。 |
ApplicationIsolationByUser | 21 | 存储首先按用户隔离,然后按应用程序隔离。 存储也被计算机隔离。 这为在任何域上下文中均可访问的应用程序提供了数据存储区。 基于应用程序的数据隔离舱需要额外的信任,原因是数据隔离舱可能会在应用程序之间提供“隧道”,从而危及特定网站中应用程序的数据隔离。 |
AssemblyIsolationByMachine | 64 | 存储首先按计算机隔离,然后按代码程序集隔离。 这为在任何域上下文中都可访问的程序集提供了数据存储区。 基于程序集的数据室需要额外的信任,因为它可能在应用程序之间提供“隧道”,该隧道会危及特定网站中应用程序的数据隔离。 |
AssemblyIsolationByRoamingUser | 96 | 存储首先按用户隔离,然后按程序集证据隔离。 当启用 Windows 用户数据漫游时,存储将漫游。 这为在任何域上下文中都可访问的程序集提供了数据存储区。 基于程序集的数据室需要额外的信任,因为它可能在应用程序之间提供“隧道”,该隧道会危及特定网站中应用程序的数据隔离。 |
AssemblyIsolationByUser | 32 | 存储首先按用户隔离,然后按代码程序集隔离。 存储也被计算机隔离。 这为在任何域上下文中都可访问的程序集提供了数据存储区。 基于程序集的数据室需要额外的信任,因为它可能在应用程序之间提供“隧道”,该隧道会危及特定网站中应用程序的数据隔离。 |
DomainIsolationByMachine | 48 | 存储首先按计算机隔离,然后按域和程序集隔离。 只有在相同应用程序的上下文内并且仅在相同的计算机上运行时,才可访问数据。 这在第三方程序集想要保留私有数据存储区时很有用。 |
DomainIsolationByRoamingUser | 80 | 存储首先按用户隔离,然后按域和程序集隔离。 当启用 Windows 用户数据漫游时,存储将漫游。 只有在相同应用程序的上下文内并且仅由相同用户运行时,才可访问数据。 这在第三方程序集想要保留私有数据存储区时很有用。 |
DomainIsolationByUser | 16 | 存储首先按用户隔离,然后按域和程序集隔离。 存储也被计算机隔离。 只有在相同应用程序的上下文内并且仅由相同用户运行时,才可访问数据。 这在第三方程序集想要保留私有数据存储区时很有用。 |
None | 0 | 不允许使用独立存储。 |
UnrestrictedIsolatedStorage | 240 | 允许在没有任何限制的情况下使用独立存储。 代码对用户存储区的任何部分均有完全访问权限,而不管域或程序集的标识如何。 独立存储的这种使用允许对独立存储数据存储区中的内容进行枚举。 |
示例
此示例演示如何告诉 CLR 此程序集中的代码需要此 IsolatedStoragePermission 程序集,并演示如何从独立存储中写入和读取代码。
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::IO::IsolatedStorage;
using namespace System::IO;
static void WriteIsolatedStorage()
{
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);
}
}
// Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
// This restricts the called methods to working only with storage files that are isolated
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction::PermitOnly, UsageAllowed = IsolatedStorageContainment::AssemblyIsolationByUser)]
int main()
{
WriteIsolatedStorage();
}
// This code produces the following output.
//
// This is some test data.
using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;
// Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
// This restricts the called methods to working only with storage files that are isolated
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public sealed class App
{
static void Main()
{
WriteIsolatedStorage();
}
private static void WriteIsolatedStorage()
{
// 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.
Option Strict On
Imports System.Security.Permissions
Imports System.IO.IsolatedStorage
Imports System.IO
' Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
' This restricts the called methods to working only with storage files that are isolated
' by user and assembly.
<IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed:=IsolatedStorageContainment.AssemblyIsolationByUser)> _
Public NotInheritable Class App
Shared Sub Main()
WriteIsolatedStorage()
End Sub
Shared Sub WriteIsolatedStorage()
' 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.
Dim s As New IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly())
Try
' Write some data out to the isolated file.
Dim sw As New StreamWriter(s)
Try
sw.Write("This is some test data.")
Finally
sw.Dispose()
End Try
Finally
s.Dispose()
End Try
' Attempt to open the file that was previously created.
Dim t As New IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly())
Try
' Read the data from the file and display it.
Dim sr As New StreamReader(t)
Try
Console.WriteLine(sr.ReadLine())
Finally
sr.Dispose()
End Try
Finally
t.Dispose()
End Try
End Sub
End Class
' This code produces the following output.
'
' Some test data.
注解
独立存储使用证据来确定应用程序或组件使用的唯一存储区域。 程序集的标识唯一地确定虚拟文件系统的根目录供该程序集使用。 因此,与其说是共享通用资源(如文件系统或注册表)的许多应用程序和组件,而且每个应用程序都有自己的文件区域本身就分配给它。
分配独立存储时使用四个基本隔离范围:
User
- 代码始终根据当前用户限定范围。 当由不同用户运行时,同一程序集将接收不同的存储。Machine
- 代码始终根据计算机限定范围。 在同一台计算机上由不同用户运行时,同一程序集将接收相同的存储。Assembly
- 代码通过强名称 ((例如 Microsoft)以加密方式标识。Office。*或 Microsoft。Office。Word) (按发布者 (基于公钥) 、URL (例如,http://www.fourthcoffee.com/process/grind.htm
按网站或按区域) )。Domain
- 根据与应用程序域关联的证据标识代码。 Web 应用程序标识派生自网站的 URL 或网页的 URL、网站或区域。 本地代码标识基于应用程序目录路径。
有关 URL、站点和区域的定义,请参阅 UrlIdentityPermission、 SiteIdentityPermission和 ZoneIdentityPermission。
这些标识分组在一起,在这种情况下,标识将相互应用,直到创建所需的独立存储。 有效分组是 User+Assembly 和 User+Assembly+Domain。 此标识分组在许多不同的应用程序中非常有用。
如果数据由域、用户和程序集存储,则数据将专用于该程序集中的代码可以访问数据。 数据存储也由运行它的应用程序隔离,因此程序集不会通过向其他应用程序公开数据来表示潜在的泄漏。
按程序集和用户隔离可用于跨多个应用程序应用的用户数据;例如,许可证信息或用户的个人信息 (名称、身份验证凭据等) 独立于应用程序。
IsolatedStorageContainment 公开用于确定是否允许应用程序使用独立存储的标志,如果是,则允许使用哪个标识组合。 它还确定是否允许应用程序将信息存储在可以与用户 (Windows漫游用户配置文件或文件夹重定向一起漫游的位置) 。