久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

GetAuthorizationGroups() 拋出異常

GetAuthorizationGroups() is throwing exception(GetAuthorizationGroups() 拋出異常)
本文介紹了GetAuthorizationGroups() 拋出異常的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

PrincipalContext context = new PrincipalContext(ContextType.Domain, "ipofmachine", "DC=xyz,DC=org", "username", "Password");

UserPrincipal userPrinciple = UserPrincipal.FindByIdentity(context, "User0"); 
var groups = userPrinciple.GetAuthorizationGroups();

if (userPrinciple != null)
{
    foreach (GroupPrincipal gp in groups)
    {
        //some thing
    }
}

我需要給予任何許可嗎?在一些博客中,我了解到如果沒有設置為包含 SID 歷史記錄的用戶,那么這將正常工作(但我認為您無法編輯組的 sid 值)

Is there any permission that I need to give? In some of the blogs I learned that if there are no users which are set to include the SID history then this will work fine (but i think you can not edit the sid values of the groups)

推薦答案

我發現將域用戶添加到本地組時存在問題,但后來該域用戶從 Active Directory 中刪除.該本地組的狀態是使用 SID 而不是顯示為成員的域用戶名.

I've found there's an issue when you add a domain user to a local group, but later that domain user is deleted out of Active Directory. The state of that local group is that instead of a domain username showing up as a member, the SID is used instead.

但是!

該 SID 不再存在于 Active Directory 中,這導致事情變得繁榮起來.

That SID doesn't exist in Active Directory anymore causing things to go boom.

當然,彈出 NoMatchingPrincipalException 的原因可能有很多,因此此代碼提供了一種解決方法.它來自 MSDN 上的一篇很棒的帖子.下面的代碼是在這里找到的修改版本:

Of course there could be many other reasons for an NoMatchingPrincipalException to pop up, so this code provides a workaround for that. It comes from a terrific post on MSDN. The code below is a modified version found here:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/9dd81553-3539-4281-addd-3eb75e6e4d5d/getauthorizationgroups-fails-with-nomatchingprincipalexception

    public static IEnumerable<Principal> getAuthorizationGroups(UserPrincipal user)
    {
        PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();
        List<Principal> ret = new List<Principal>();
        var iterGroup = groups.GetEnumerator();
        using (iterGroup)
        {
            while (iterGroup.MoveNext())
            {
                try
                {
                    Principal p = iterGroup.Current;
                    Console.WriteLine(p.Name);
                    ret.Add(p);
                }
                catch (NoMatchingPrincipalException pex)
                {
                    continue;
                }
            }
        }
        return ret;
    }

這篇關于GetAuthorizationGroups() 拋出異常的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 97超碰站 | 日韩爱爱网 | 99福利| a在线免费观看视频 | 午夜精品久久久久久久久久久久 | 国产欧美日韩一区 | 亚洲国产一区二区在线 | 在线亚洲欧美 | 国产精品欧美一区二区三区 | 久草网址 | 福利影院在线看 | 神马福利 | 国产精品伦一区二区三级视频 | 成人亚洲视频 | 国产aaaaav久久久一区二区 | 久久99精品国产 | ww亚洲ww亚在线观看 | www.亚洲免费 | 久色网| 在线观看国产视频 | 91欧美激情一区二区三区成人 | 精品视频在线观看 | 亚洲欧美精品久久 | 日韩欧美在线观看 | 欧美日韩视频网站 | 欧美三级在线 | 久国产 | 国产探花在线精品一区二区 | 久久久久久久久久久久久久国产 | 欧美日韩在线观看视频网站 | 殴美一级片| 欧美一级淫片免费视频黄 | 中文字幕日韩专区 | 精品在线免费观看视频 | 中文字幕亚洲一区二区三区 | 午夜视频免费在线观看 | 久久激情视频 | 精品福利在线 | 亚洲美女一区二区三区 | 欧美精品中文字幕久久二区 | 国产精品久久 |