SecurityContext 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
Code Access Security is not supported or honored by the runtime.
封装并传播在线程间传输的执行上下文的所有安全相关数据。 此类不能被继承。
public ref class SecurityContext sealed : IDisposablepublic ref class SecurityContext sealedpublic sealed class SecurityContext : IDisposable[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed class SecurityContext : IDisposablepublic sealed class SecurityContexttype SecurityContext = class
    interface IDisposable[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type SecurityContext = class
    interface IDisposabletype SecurityContext = classPublic NotInheritable Class SecurityContext
Implements IDisposablePublic NotInheritable Class SecurityContext- 继承
- 
				SecurityContext
- 属性
- 实现
注解
注意
代码访问安全性 (CAS) 已在所有版本的 .NET Framework 和 .NET 中弃用。 如果使用与 CAS 相关的 API,最新版本的 .NET 不会遵循 CAS 注释,并会生成错误。 开发人员应寻求用于完成安全任务的替代方法。
备注
从 .NET 6 开始,此类型标记为已过时。
对象SecurityContext捕获逻辑线程的所有安全相关信息,包括 和 CompressedStack 对象中包含的WindowsIdentity信息。 此配置允许在跨异步线程复制和传输 时 SecurityContext 自动传播堆栈上的 Windows 标识和安全元素。
注意
公共语言运行时 (CLR) 识别使用托管代码执行的模拟操作,而不识别在托管代码外部执行的模拟操作,例如通过平台调用非托管代码或直接调用 Win32 函数。 只有托管 WindowsIdentity 对象可以跨异步点流动,除非 alwaysFlowImpersonationPolicy 元素已设置为 true (<alwaysFlowImpersonationPolicy enabled="true"/>) 。 将 alwaysFlowImpersonationPolicy 元素设置为 true 指定 Windows 标识始终跨异步点流动,而不考虑模拟的执行方式。 有关跨异步点流动非托管模拟的详细信息,请参阅 <alwaysFlowImpersonationPolicy> 元素。
SecurityContext是较大 ExecutionContext 和 的一部分,在流或迁移时流ExecutionContext或迁移。
重要
此类型实现 IDisposable 接口。 在使用完类型后,您应直接或间接释放类型。 若要直接释放类型,请在 try/catch 块中调用其 Dispose 方法。 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。
方法
| 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) |