从asp.net获取验证AD用户objectGuid
发布时间:2020-12-16 00:18:35 所属栏目:asp.Net 来源:网络整理
导读:我在ASP.NET应用程序中使用Windows身份验证.我想知道如何最好地从当前登录的用户获取objectGuid? 此致,埃吉尔. 解决方法 您可以使用System.DirectoryServices命名空间执行此操作. Dim entry As DirectoryServices.DirectoryEntryDim mySearcher As System.D
我在ASP.NET应用程序中使用Windows身份验证.我想知道如何最好地从当前登录的用户获取objectGuid?
此致,埃吉尔. 解决方法
您可以使用System.DirectoryServices命名空间执行此操作.
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 可能有更好的方法来做到这一点,但这是有效的! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – Orchard CMS中的SignalR聊天模块
- asp.net – 在某些页面上禁用ScriptManager
- 互联网级监控系统必备-时序数据库之Influxdb集群及踩过的坑
- asp.net-core – 为什么这违反了类型参数’TUser’的约束?
- asp.net-mvc – 当参数名称需要不同时,如何重用远程验证方法
- asp.net-mvc – ASP.NET MVC CookieTempDataProvider:有什
- ListBox中的选定项目是否有ASP.NET集合?
- asp.net-mvc – 在ASP.NET MVC中将多个对象暴露给视图的最佳
- asp.net-mvc – 最初在使用AuthorizeAttribute时设置Return
- asp.net – 如何将HTML片段(作为委托?)传递给声明性Razor