SecurityContext 類別

定義

封裝並傳播所有安全性相關數據,以便跨線程傳輸的執行內容。 此類別無法獲得繼承。

public ref class SecurityContext sealed
public ref class SecurityContext sealed : IDisposable
public sealed class SecurityContext
public sealed class SecurityContext : IDisposable
type SecurityContext = class
type SecurityContext = class
    interface IDisposable
Public NotInheritable Class SecurityContext
Public NotInheritable Class SecurityContext
Implements IDisposable
繼承
SecurityContext
實作

備註

注意事項

.NET Framework 和 .NET 的所有版本中,代碼存取安全性(CAS)已被棄用。 最新版本的 .NET 不會接受 CAS 註釋,如果使用 CAS 相關 API,則會產生錯誤。 開發人員應尋求其他方法來完成安全任務。

Note

此類型自 .NET 6 起被標記為過時。

物件SecurityContext會擷取邏輯執行緒中所有與安全相關的資訊,包括 和 CompressedStack 物件中所包含WindowsIdentity的資訊。 此配置允許在複製並傳輸 SecurityContext 跨非同步執行緒時,能自動傳播Windows身份與堆疊上的安全元素。

Note

Common Language Runtime (CLR) 知道只使用 Managed 程式代碼執行的模擬作業,而不是在 Managed 程式代碼外部執行的模擬作業,例如透過平臺叫用至 Unmanaged 程式代碼,或透過直接呼叫 Win32 函式。 只有受管理 WindowsIdentity 物件能跨越非同步點,除非元素 alwaysFlowImpersonationPolicy 被設定為 true<alwaysFlowImpersonationPolicy enabled="true"/>)。 將 alwaysFlowImpersonationPolicy 元素設為 true 則指定 Windows 身份總是在非同步點間流動,無論模擬方式如何。 欲了解更多關於跨非同步點流動非管理模擬的資訊,請參閱 <alwaysFlowImpersonationPolicy> Element

它是 SecurityContext 較大 ExecutionContext 部分的一部分,當流動 ExecutionContext 或遷移時,會流動或遷移。

Important

此類型會實作 IDisposable 介面。 當您完成使用這個物品後,應直接或間接地處理它。 若要直接處置類型,請在 Disposetry/ 區塊中呼叫其 catch 方法。 若要間接處置它,請使用語言建構,例如 using (C#) 或 Using (在 Visual Basic 中)。 如需詳細資訊,請參閱介面主題中的 <使用實作 IDisposable 的物件>一節。

方法

名稱 Description
Capture()

擷取當前執行緒的安全上下文。

CreateCopy()

建立目前安全上下文的副本。

Dispose()

釋放目前類別實例 SecurityContext 所使用的所有資源。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsFlowSuppressed()

判斷安全上下文的流動是否被抑制。

IsWindowsIdentityFlowSuppressed()

判斷目前安全情境中 Windows 身份部分的流動是否被抑制。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
RestoreFlow()

恢復非同步執行緒間的安全上下文流動。

Run(SecurityContext, ContextCallback, Object)

在當前執行緒中,以指定的安全情境執行指定方法。

SuppressFlow()

抑制非同步執行緒間安全上下文的流動。

SuppressFlowWindowsIdentity()

抑制當前安全上下文中 Windows 身份部分在非同步執行緒間的流動。

ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於