我在 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!
这篇关于从 asp.net 获取验证 AD 用户 objectGuid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Asp.net System.Web.HttpContext.Current.Session 在 global.asaAsp.net System.Web.HttpContext.Current.Session null in global.asax(Asp.net System.Web.HttpContext.Current.Session 在 global.asax 中为 null)
捕获的异常本身为空!Caught exception is null itself !(捕获的异常本身为空!)
空文本框被视为空字符串还是 null?Is an empty textbox considered an empty string or null?(空文本框被视为空字符串还是 null?)
UserPrincipals.GetAuthorizationGroups 枚举组时发生错误UserPrincipals.GetAuthorizationGroups An error (1301) occurred while enumerating the groups. After upgrading to Server 2012 Domain Controller(UserPrinc
使用 PrincipalSearcher 查找带有“或"的用户参数Using PrincipalSearcher to find users with quot;orquot; parameters(使用 PrincipalSearcher 查找带有“或的用户参数)
递归获取 Active Directory 组的成员,即包括子组Get members of an Active Directory group recursively, i.e. including subgroups(递归获取 Active Directory 组的成员,即包括子组)