获取验证AD用户asp.net的objectGUID [英] Getting authenticate AD users objectGuid from asp.net

查看:593
本文介绍了获取验证AD用户asp.net的objectGUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是ASP.NET应用程序中的Windows身份验证。我想知道如何以最佳方式获得的objectGUID从当前登录的用户?

I am using windows authentication within an ASP.NET application. I am wondering how to best get the objectGuid from the currently logged in user?

问候,埃吉尔。

推荐答案

您可以使用System.DirectoryServices命名空间做到这一点。

You can do this with the System.DirectoryServices namespace.

Dim entry As DirectoryServices.DirectoryEntry
Dim mySearcher As System.DirectoryServices.DirectorySearcher
Dim result As System.DirectoryServices.SearchResult
Dim myEntry As DirectoryEntry
Dim domainName As String
Dim userId As String
Dim objectGuid As Guid

'Split the username into domain and userid parts
domainName = Page.User.Identity.Name.Substring(0, Page.User.Identity.Name.IndexOf("\"))
userId = Page.User.Identity.Name.Substring(Page.User.Identity.Name.IndexOf("\") + 1)

'Start at the top level domain
entry = New DirectoryEntry(domainName)

mySearcher = New DirectorySearcher(entry)

'Build a filter for just the user
mySearcher.Filter = ("(&(anr=" & userId & ")(objectClass=user))")

'Get the search result ...
result = mySearcher.FindOne

'... and then get the AD entry that goes with it
myEntry = result.GetDirectoryEntry

'The Guid property is the objectGuid
objectGuid = myEntry.Guid

有可能是一个更好的方式来做到这一点,但这个工作!

There might be a better way to do this, but this works!

这篇关于获取验证AD用户asp.net的objectGUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆