按用户和程序集隔离

更新:2007 年 11 月

当需要从任何应用程序域都可以访问程序集使用的数据存储区时,按用户和程序集隔离比较合适。通常,在这种情况下,独立存储用于存储跨多个应用程序应用的数据(例如用户的名称或许可证信息),这些数据不依赖于任何特定的应用程序。要访问按用户和程序集隔离的存储,代码必须受信以在应用程序之间传输信息。通常,允许在 Intranet 上使用按用户和程序集隔离,但不允许在 Internet 上使用。调用 IsolatedStorageFile 的静态 GetStore 方法并传入用户和程序集 IsolatedStorageScope 将返回具有这种隔离的存储。

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

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

有关使用证据参数的示例,请参见 IsolatedStorageFile.GetStore(IsolatedStorageScope, Evidence, Type, Evidence, Type)

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

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

请参见

概念

隔离的类型

按用户、域和程序集隔离

参考

GetUserStoreForAssembly

其他资源

执行独立存储任务