Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查Windows标识是否正在模拟?_C#_Windows_Impersonation - Fatal编程技术网

C# 如何检查Windows标识是否正在模拟?

C# 如何检查Windows标识是否正在模拟?,c#,windows,impersonation,C#,Windows,Impersonation,是否可以检查WindowsIdentity是否正在模拟?是。只需检查WindowsIdentity类的属性 从MSDN: 获取用户的模拟级别 匿名-服务器进程无法获取有关客户端的标识信息,也无法模拟客户端 委派-服务器进程可以在远程系统上模拟客户端的安全上下文 标识-服务器进程可以获取有关客户端的信息 模拟-服务器进程可以在其本地系统上模拟客户端的安全上下文 无 代码段(已修改): 输出: 更多 我不确定这是否有意义。你想做什么?谢谢,我想可以。 var identity = Window

是否可以检查WindowsIdentity是否正在模拟?

是。只需检查
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);
    }
}