【问题标题】:Property value returned by DirectorySearcher and SearchResponse are of different type System._comobject and Byte arrayDirectorySearcher 和 SearchResponse 返回的属性值是不同类型的 System._comobject 和 Byte 数组
【发布时间】:2012-11-18 06:25:21
【问题描述】:

我正在开发一个网站来管理活动目录。我想检查用户是否有权更改密码。所以我必须找到 "ntSecurityDescriptor" 属性值,然后我必须将其转换为 IADsSecurityDescriptor。

现在,如果我使用 DirectorySearcher 类,则属性值为 System._ComObject 类型,并且可以轻松转换为 IADsSecurityDescriptor。但是当我使用 LdapConnection 和 SearchResponse 时,我会得到类型的属性值。

byte[] array which is unale to cast to IADsSecityDescriptor.

我遇到错误

Unable to cast System.Byte[] to IADsSecurityDescriptor

SearchResponse 是否存在问题,或者我使用了某种类型的转换技术来实现这一点?我在使用 DirectoryEntry 类时遇到了一些问题,所以我只能使用 LdapConnction 类。

【问题讨论】:

标签: asp.net c#-4.0 active-directory ldap openldap


【解决方案1】:

我终于找到了我的问题的答案。此类将 byte[] 转换为有效的安全描述符 comobject。

ActiveDs.ADsSecurityUtility secUtility = new ActiveDs.ADsSecurityUtility();
ActiveDs.IADsSecurityDescriptor sd = (IADsSecurityDescriptor)secUtility.ConvertSecurityDescriptor((byte[])attribute[0], (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_RAW, (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);

【讨论】:

    【解决方案2】:

    我认为您应该努力尝试使用 DirectoryEntry 方法。 尝试使用 LdapConnection 操作 AD 对象时,您将遇到非常困难。

    如果你想继续Ldap的方式,在快速搜索之后,我会尝试原生(这个词说明一切)自动化功能。里面似乎有一些有趣的东西,比如:

    ConvertStringSecurityDescriptorToSecurityDescriptor

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa376401%28v=vs.85%29.aspx

     C# syntax
    
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("Advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
    internal static extern bool ConvertStringSecurityDescriptorToSecurityDescriptor(string StringSecurityDescriptor, uint StringSDRevision, ref IntPtr SecurityDescriptor, IntPtr SecurityDescriptorSize);
    

    【讨论】:

    • 感谢您的回复。这对我来说太紧急了,这就是我输入多个问题的原因。我发现 RawSecurityDescriptor 类在其构造函数中接受 byte[],并且我得到了具有 SecurityDescriptor comobject 等属性的对象。但我无法将其转换为 IADsSecurityDescriptor。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 2022-08-23
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2022-06-12
    相关资源
    最近更新 更多