按用户、域和程序集隔离

更新:2007 年 11 月

如果应用程序使用需要私有数据存储区的第三方程序集,隔离存储可用于存储私有数据。按用户、域和程序集隔离确保只有当在程序集创建存储区时运行的应用程序使用该程序集时,并且只有当为其创建存储区的用户运行该应用程序时,只有给定程序集中的代码才可以访问数据。按用户、域和程序集隔离使第三方程序集不能向其他应用程序泄露数据。如果您知道要使用隔离存储但不确定要使用哪种类型的隔离,这种隔离类型应该是您的默认选择。调用 IsolatedStorageFile 的静态 GetStore 方法并传入用户、域和程序集,IsolatedStorageScope 将返回具有这种隔离的存储。

下面的代码示例检索按用户、域和程序集隔离的存储区。可通过 isoFile 对象访问该存储区。

Dim isoStore As IsolatedStorageFile
isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);

另一个方法可作为快捷方式,如下面的代码示例中所示。此快捷方式无法用于打开能够漫游的存储区,在这种情况下,请使用 GetStore

Dim isoStore As IsolatedStorageFile
isoStore = IsolatedStorageFile.GetUserStoreForDomain()
IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForDomain();

请参见

概念

隔离的类型

按用户和程序集隔离

其他资源

执行独立存储任务