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

GetAuthorizationGroups() 拋出異常

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

問題描述

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
    }
}

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

推薦答案

我發(fā)現(xiàn)將域用戶添加到本地組時(shí)存在問題,但后來該域用戶從 Active Directory 中刪除.該本地組的狀態(tài)是使用 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 中,這導(dǎo)致事情變得繁榮起來.

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

當(dāng)然,彈出 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;
    }

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

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

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 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#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時(shí)如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 免费看国产一级特黄aaaa大片 | 1000部精品久久久久久久久 | 国产99久久 | 天天射天天干 | 国产第一亚洲 | 九九久久精品 | 本地毛片 | 国产99久久精品一区二区永久免费 | 欧美精品久久久 | 国产精品欧美一区二区 | 成人精品| 亚洲精品国产a久久久久久 中文字幕一区二区三区四区五区 | 国产一二区视频 | 亚洲免费一区 | 日韩av在线中文字幕 | 午夜免费视频 | 在线观看免费av网 | 亚洲 中文 欧美 日韩 在线观看 | 精品国产一区二区三区免费 | 色婷婷亚洲一区二区三区 | 91成人精品 | 亚洲免费在线 | 狠狠av | 成人精品久久日伦片大全免费 | 国产视频久久久 | 日本在线看片 | 国产一区二区在线看 | 免费在线一区二区 | 国内精品久久久久久 | 久久机热 | 久热精品免费 | 欧美九九 | 国产a爽一区二区久久久 | 美女视频久久 | 日韩成人免费av | 91一区二区三区在线观看 | 欧美精品一区二区三区在线播放 | 亚洲国产一区二区视频 | 日韩av视屏 | 日韩美香港a一级毛片免费 国产综合av | 中文字幕在线视频网站 |