asp.net C VB.NET C 如何使用Active Directory将SID转换为组名
发布时间:2023-12-21 14:43:06 所属栏目:asp.Net 来源:DaWei
导读: 使用VB.NET,如何使用Active Directory将sid转换为组名?
例如:我需要获得“group_test”而不是“S-1-5-32-544”
我正在使用的代码是:
Public ReadOnly Property Groups As Id
例如:我需要获得“group_test”而不是“S-1-5-32-544”
我正在使用的代码是:
Public ReadOnly Property Groups As Id
使用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―-编辑―C (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-4 – MVC4捆绑GZIP和头文件
- asp.net – 如何在Windows Phone中开发Google地图
- asp.net – 是否有可能过滤SignalR中的接收器?
- asp.net-mvc – 不应加载引用程序集以执行
- MVC SessionStateAttribute不作为全局属性
- asp.net C 我应该在.gitingore文件中包含.vs文件夹吗?
- asp.net-mvc – ASP.NET MVC:路由中的命名空间
- 增加ASP.NET站点的executionTimeout和maxRequestLength是否
- asp.net-mvc – TempData在第二个请求后不会被破坏
- asp.net-mvc – ASP.net身份在删除外部帐户后停止分发外部C
推荐文章
站长推荐
- .Net 更容易的使用配置文件 SuperConfig
- asp.net-mvc – ASP.NET MVC/C++#:可以使用Html
- asp.net – 干净的方式来防止输入按钮提交表单
- 使用System.Net.Mail中的SMTP发送邮件(带附件)
- asp.net – 如何在Visual Studio中添加NUnit
- asp.net – 避免在web.config中提供服务器连接字
- asp.net-mvc – ASP.NET MVC查看引擎解析顺序
- asp.net-mvc-3 – “区域”文件夹中的样式,脚本和
- asp.net – 我可以通过编程方式禁用更新面板吗?
- asp.net-core – asp.net核心身份中的多个SubDom
热点阅读
- asp.net-core C 如何使用ASP.NET注册OData
- asp.net C MVC4 C ContextDependentView C
- asp.net-mvc-3 C 如何从ASP.NET MVC#输出中
- asp.net-mvc C 已经使用相同的参数类型定义
- ASP.Net C AJAX UpdatePanel中的Javascript
- asp.net-mvc C ASP.NET MVC中的WebApi [Fro
- asp.net-mvc C 使用AD的ASP.NET MVC表单Aut
- asp.net C 适用于多个用户的EWS通知中心
- asp.net-mvc C 未在ELMAH中记录的错误
- asp.net-mvc C MVC应用程序中的随机数生成