获得从公元扩展属性?公元、属性

由网友(晴☆天)分享简介:我从我们的网络团队的一员得到这个您可以看到,extensionAttribute2中有一个值。我如何可以检索该值 - 我看不到extensionAttributes anywere在UserPrincipal对象 - 除非我失去了一些东西。我已经回到一个水平进一步尝试下面的:UserPrincipal MYUSER...

我从我们的网络团队的一员得到这个

您可以看到,extensionAttribute2中有一个值。我如何可以检索该值 - 我看不到extensionAttributes anywere在UserPrincipal对象 - 除非我失去了一些东西。

我已经回到一个水平进一步尝试下面的:

  UserPrincipal MYUSER = UserPrincipal.FindByIdentity(CON,identityName);

        的DirectoryEntry德=(myUser.GetUnderlyingObject(),为的DirectoryEntry);

        如果(德!= NULL)
        {
            //去为那些属性,做你需要做的
            如果(de.Properties.Contains(extensionAttribute2))
            {
                返回de.Properties [extensionAttribute2] [0]的ToString();
            }
            其他
            {
                返回的String.Empty;
            }
        }
 

不过,这并不奏效 - 调试这个有可用的大约40属性,但没有对extensionAttribute2

解决方案

使用marc_s使用添加以下的code:

 公共静态新UserPrincipalEx FindByIdentity(PrincipalContext背景下,串identityValue)
        {
            返程(UserPrincipalEx)FindByIdentityWithType(背景下的typeof(UserPrincipalEx),identityValue);
        }

        //实现重载的搜索方法FindByIdentity。
        公共静态新UserPrincipalEx FindByIdentity(PrincipalContext背景下,IdentityType identityType,串identityValue)
        {
            返程(UserPrincipalEx)FindByIdentityWithType(背景下的typeof(UserPrincipalEx),identityType,identityValue);
        }
 
CF高级角色通用扩展栏位怎么获得 属性槽获取方法

I got this from a member of our Network Team:

You can see that extensionAttribute2 has a value in it. How can I retrieve this value - I cannot see extensionAttributes anywere in UserPrincipal object - unless I am missing something.

I have went back a level further and tried the below:

        UserPrincipal myUser = UserPrincipal.FindByIdentity(con, identityName);

        DirectoryEntry de = (myUser.GetUnderlyingObject() as DirectoryEntry);

        if (de != null)
        {
            // go for those attributes and do what you need to do
            if (de.Properties.Contains("extensionAttribute2"))
            {
                return de.Properties["extensionAttribute2"][0].ToString();
            }
            else
            {
                return string.Empty;
            }
        }

However this does not work - debugging this there are about 40 properties available but none for extensionAttribute2

解决方案

Using the code that marc_s used add the following:

        public static new UserPrincipalEx FindByIdentity(PrincipalContext context, string identityValue)
        {
            return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityValue);
        }

        // Implement the overloaded search method FindByIdentity. 
        public static new UserPrincipalEx FindByIdentity(PrincipalContext context, IdentityType identityType, string identityValue)
        {
            return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityType, identityValue);
        }

阅读全文

相关推荐

最新文章