C# 如何检查Windows标识是否正在模拟?
是否可以检查WindowsIdentity是否正在模拟?是。只需检查C# 如何检查Windows标识是否正在模拟?,c#,windows,impersonation,C#,Windows,Impersonation,是否可以检查WindowsIdentity是否正在模拟?是。只需检查WindowsIdentity类的属性 从MSDN: 获取用户的模拟级别 匿名-服务器进程无法获取有关客户端的标识信息,也无法模拟客户端 委派-服务器进程可以在远程系统上模拟客户端的安全上下文 标识-服务器进程可以获取有关客户端的信息 模拟-服务器进程可以在其本地系统上模拟客户端的安全上下文 无 代码段(已修改): 输出: 更多 我不确定这是否有意义。你想做什么?谢谢,我想可以。 var identity = Window
WindowsIdentity
类的属性
从MSDN:
获取用户的模拟级别
- 匿名-服务器进程无法获取有关客户端的标识信息,也无法模拟客户端
- 委派-服务器进程可以在远程系统上模拟客户端的安全上下文
- 标识-服务器进程可以获取有关客户端的信息
- 模拟-服务器进程可以在其本地系统上模拟客户端的安全上下文
- 无
我不确定这是否有意义。你想做什么?谢谢,我想可以。
var identity = WindowsIdentity.GetCurrent();
Console.WriteLine("Before impersonation: " + identity.Name);
Console.WriteLine("ImpersonationLevel: {0}", identity.ImpersonationLevel);
// Use the token handle returned by LogonUser.
using (WindowsIdentity newId = new
WindowsIdentity(safeTokenHandle.DangerousGetHandle()))
{
using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
{
// Check the identity.
identity = WindowsIdentity.GetCurrent();
Console.WriteLine("After impersonation: "+ identity.Name);
Console.WriteLine("ImpersonationLevel: {0}", identity.ImpersonationLevel);
}
}