IsolatedStorageContainment 列舉

定義

警告

Code Access Security is not supported or honored by the runtime.

指定隔離儲存區 (Isolated Storage) 的允許用法。

C#
[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
C#
[System.Serializable]
public enum IsolatedStorageContainment
C#
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum IsolatedStorageContainment
C#
public enum IsolatedStorageContainment
繼承
IsolatedStorageContainment
屬性

欄位

名稱 Description
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 也會示範如何撰寫和讀取隔離儲存區。

C#
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.

備註

注意

程式代碼啟用安全性 (CAS) 在所有版本的 .NET Framework 和 .NET 中已被取代。 最新版本的 .NET 不接受 CAS 批注,並在使用 CAS 相關 API 時產生錯誤。 開發人員應尋求替代方案來完成安全性工作。

隔離儲存區會使用辨識項來判斷應用程式或元件要使用的唯一儲存區域。 元件的身分識別會唯一決定虛擬文件系統的根目錄,以供該元件使用。 因此,與其共用一般資源的許多應用程式和元件,例如文件系統或登錄,每個都有本身的檔案區域原本就指派給它。

指派隔離儲存區時,會使用四個基本隔離範圍:

  • User - 程序代碼一律會根據目前的用戶來設定範圍。 由不同的使用者執行時,相同的元件會收到不同的存放區。

  • Machine - 程序代碼一律會根據計算機設定範圍。 相同元件在相同計算機上由不同的用戶執行時,會收到相同的存放區。

  • Assembly- 以強名稱 (識別程序代碼,例如 Microsoft.Office.* 或 Microsoft.Office。Word) ,依發行者 (根據公鑰) 、依 URL (,例如, http://www.fourthcoffee.com/process/grind.htm 依) 、依網站或依區域。

  • Domain - 根據與應用程式域相關聯的辨識項來識別程序代碼。 Web 應用程式身分識別衍生自網站的 URL,或是網頁的 URL、網站或區域。 本機程式代碼身分識別是以應用程式目錄路徑為基礎。

如需 URL、網站和區域的定義,請參閱 UrlIdentityPermissionSiteIdentityPermissionZoneIdentityPermission

這些身分識別會分組在一起,在此情況下,系統會逐一套用身分識別,直到建立所需的隔離儲存區為止。 有效的群組為 User+Assembly 和 User+Assembly+Domain。 此身分識別群組在許多不同的應用程式中很有用。

如果數據是由網域、使用者和元件所儲存,則數據在只有該元件中的程式代碼可以存取數據。 數據存放區也會由執行所在的應用程式隔離,因此元件不會藉由將數據公開給其他應用程式來表示潛在的外泄。

依元件和用戶隔離可用於跨多個應用程式套用的用戶數據;例如,授權資訊或用戶的個人資訊 (名稱、驗證認證等) 與應用程式無關。

IsolatedStorageContainment 會公開旗標,判斷是否允許應用程式使用隔離儲存區,如果是,則允許使用哪一個身分識別組合。 它也會決定是否允許應用程式將資訊儲存在可以與使用者漫遊的位置 (Windows 漫遊使用者策略檔或資料夾重新導向) 。

適用於

產品 版本 (已過時)
.NET (6, 7, 8, 9)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1 (5, 6, 7, 8, 9)

另請參閱