Share via


依據使用者、定義域和組件的隔離

如果應用程式使用需要私用 (Private) 資料存放區的協力廠商組件,可使用隔離儲存區來儲存私用資料。依據使用者、定義域和組件的隔離會確保只有指定組件中的程式碼可以存取資料,並且只有當在組件建立存放區時執行的應用程式使用組件時,以及只有當為其建立存放區的使用者執行應用程式時。依據使用者、定義域和組件的隔離避免協力廠商組件洩漏資料給其他應用程式。這個隔離類型應該是您的預設選擇,如果您知道要使用隔離儲存區,但不確定要使哪個隔離類型的話。呼叫 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();

請參閱

概念

隔離的類型
依據使用者和組件的隔離

其他資源

執行隔離儲存區工作