asp.net – VB.NET – 如何使用Active Directory将SID转换为组名
发布时间:2021-03-30 17:15:08  所属栏目:asp.Net  来源:互联网 
            导读:使用VB.NET,如何使用Active Directory将sid转换为组名? 例如:我需要获得“group_test”而不是“S-1-5-32-544” 我正在使用的代码是: Public ReadOnly Property Groups As IdentityReferenceCollection Get Dim irc As IdentityReferenceCol
                
                
                
            | 
                         使用VB.NET,如何使用Active Directory将sid转换为组名? 例如:我需要获得“group_test”而不是“S-1-5-32-544” 我正在使用的代码是: Public ReadOnly Property Groups As IdentityReferenceCollection
    Get
        Dim irc As IdentityReferenceCollection
        Dim ir As IdentityReference
        irc = WindowsIdentity.GetCurrent().Groups
        Dim strGroupName As String
        For Each ir In irc
            Dim mktGroup As IdentityReference = ir.Translate(GetType(NTAccount))
            MsgBox(mktGroup.Value)
            Debug.WriteLine(mktGroup.Value)
            strGroupName = mktGroup.Value.ToString
        Next
        Return irc
    End Get
End Property 
 或类似的东西? currentUser = WindowsIdentity.GetCurrent()
        For Each refGroup As IdentityReference In currentUser.Groups
            Dim acc As NTAccount = TryCast(refGroup.Translate(GetType(NTAccount)),NTAccount)
            If AdminGroupName = acc.Value Then
                ret = "999"
            End If
            If UsersGroupName = acc.Value Then
                ret = "1"
            End If 
 你将如何适应这段代码? (如果用户在xx组中,请在下拉列表中显示xx组) For Each UserGroup In WindowsIdentity.GetCurrent().Groups
            If mktGroup.Value = "BIG" Then
                Dim Company = ac1.Cast(Of MarketingCompany).Where(Function(ac) ac.MarketingCompanyShort = "BIG").FirstOrDefault
                If Company IsNot Nothing Then
                    marketingCo.Items.Add(String.Format("{0} | {1}",Company.MarketingCompanyShort,Company.MarketingCompanyName))
                End If
            End If
        Next
解决方法这是一个用C#编写的简单方法,我认为这并不难以适应:/* Retreiving object from SID
  */
  string SidLDAPURLForm = "LDAP://WM2008R2ENT:389/<SID={0}>";
  System.Security.Principal.SecurityIdentifier sidToFind = new System.Security.Principal.SecurityIdentifier("S-1-5-21-3115856885-816991240-3296679909-1106");
  DirectoryEntry userEntry = new DirectoryEntry(string.Format(SidLDAPURLForm,sidToFind.Value));
  string name = userEntry.Properties["cn"].Value.ToString(); 
 由于REFLECTOR,它在VB .NET中 Dim SidLDAPURLForm As String = "LDAP://WM2008R2ENT:389/<SID={0}>"
Dim sidToFind As New SecurityIdentifier("S-1-5-21-3115856885-816991240-3296679909-1106")
Dim userEntry As New DirectoryEntry(String.Format(SidLDAPURLForm,sidToFind.Value))
Dim name As String = userEntry.Properties.Item("cn").Value.ToString 
 —-编辑—– Private Shared Sub Main(args As String())
    Dim currentUser As WindowsIdentity = WindowsIdentity.GetCurrent()
For Each iRef As IdentityReference In currentUser.Groups
        Console.WriteLine(iRef.Translate(GetType(NTAccount)))
    Next
End Sub                        (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- 学习:正则表达式的基本语法
 - asp.net-web-api – WebAPI:403在发布网站后被禁止
 - 单元测试 – 如何在ASP MVC 5(Microsoft.AspNet.Identity)中
 - ASP.Net 2中的上传文件在哪里?
 - asp.net-core – 加密ASP.Net Core中的连接字符串和其他配置
 - asp.net – 在部分视图中强制使用没有Html.BeginForm / Aja
 - asp.net中XML如何做增删改查操作
 - ASP.NET微信公众号用于给指定OpenId用户发送红包
 - iis-7.5 – 使用虚拟目录/应用程序在IIS中托管ASP.NET 5 We
 - asp.net-mvc – 如何在RegularExpression中忽略大小写?
 
推荐文章
            站长推荐
            - asp.net-mvc – 在MVC命令,优先级和功能问题中授
 - asp.net-mvc – 如何在ASP.NET MVC中传递页面的元
 - asp.net-web-api – WebAPI 2属性路由启用会话状
 - 如何单元测试我的asp.net-mvc控制器的OnActionEx
 - asp.net – IIS Express(WebMatrix)打开外部连接
 - asp.net-mvc – 为什么我得到一个“无法更新Enti
 - asp.net – 如何检查SQL Server代理是否正在运行
 - asp.net-mvc – .Net 4.5.1框架的maxRequestLeng
 - asp.net-mvc – 值不能为空或为空.参数名称:con
 - ASP.NET Core使用SkiaSharp实现验证码的示例代码
 
热点阅读
            