第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Active Directory中獲取用戶組?(C#,asp.net)

如何在Active Directory中獲取用戶組?(C#,asp.net)

aluckdog 2019-12-10 10:49:25
我使用此代碼來獲取當前用戶的組。但是我想手動給用戶,然后得到他的組。我怎樣才能做到這一點?using System.Security.Principal;public ArrayList Groups(){    ArrayList groups = new ArrayList();    foreach (IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)    {        groups.Add(group.Translate(typeof(NTAccount)).ToString());    }    return groups;}
查看完整描述

3 回答

?
慕仙森

TA貢獻1827條經(jīng)驗 獲得超8個贊

GetAuthorizationGroups()找不到嵌套的組。要真正獲得給定用戶所屬的所有組(包括嵌套組),請嘗試以下操作:


using System.Security.Principal


private List<string> GetGroups(string userName)

{

    List<string> result = new List<string>();

    WindowsIdentity wi = new WindowsIdentity(userName);


    foreach (IdentityReference group in wi.Groups)

    {

        try

        {

            result.Add(group.Translate(typeof(NTAccount)).ToString());

        }

        catch (Exception ex) { }

    }

    result.Sort();

    return result;

}

我try/catch之所以使用,是因為在一個非常大的廣告中,我在200個組中有2個例外,因為有些SID不再可用。(該Translate()調用執(zhí)行SID->名稱轉換。)


查看完整回答
反對 回復 2019-12-10
  • 3 回答
  • 0 關注
  • 803 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號