当用户登录到asp页面时获取nt sid

时间:2011-03-15 04:06:54

标签: c# asp.net authentication

我想在访问我的页面时为了安全目的而抓取用户NT SID ..

这种事情

S-1-5-21-1614280859-2041256729-1847403543-2152

我似乎无法弄清楚这一点..

我看到一篇帖子指导OP去写一本书,但我不想买一整本书只做一件事。在那篇文章中,他们提到ObjectSID是安全令牌的一部分,但我不知道如何实现这个目标。

任何帮助将不胜感激。

谢谢..

感谢Simon的解决方案:

IntPtr logonToken = WindowsIdentity.GetCurrent().Token;
WindowsIdentity windowsId = new WindowsIdentity(logonToken);
string strSID = windowsId.User.ToString();

1 个答案:

答案 0 :(得分:2)

看起来你想要WindowsIdentity类。

您可以使用WindowsIdentity.GetCurrent()获取当前身份,然后阅读User属性以获取该用户的SecurityIdentifier