IsolatedStorageContainment 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
Code Access Security is not supported or honored by the runtime.
指定隔離儲存區 (Isolated Storage) 的允許用法。
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漫遊使用者設定檔或資料夾重新導向一起漫遊的位置,) 。