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);
}
}
1条答案
按热度按时间u3r8eeie1#
是的。只需检查
WindowsIdentity
类的ImpersonationLevel属性。来自MSDN:
获取用户的模拟级别
*匿名-服务器进程无法获取客户端的标识信息,也无法模拟客户端
*Delegation-服务器进程可以在远程系统上模拟客户端的安全上下文
*标识-服务器进程可以获取客户端的信息...
*模拟-服务器进程可以在其本地系统上模拟客户端的安全上下文。
*无
代码片段(修改后的MSDN example):
字符串
输出量:
x1c 0d1x的数据
查看更多
Tell me more的