Find username from Active Directory using email id

前端 未结 2 888
孤街浪徒
孤街浪徒 2021-01-13 03:34

I am finding user name from Active Directory by passing email id. It is working fine. But it takes 30-40 seconds to get the username. Is there any other better way to find t

2条回答
  •  佛祖请我去吃肉
    2021-01-13 03:53

    using System.DirectoryServices.AccountManagement;
    
    // Lock user
    using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
    {
        UserPrincipal yourUser = UserPrincipal.FindByIdentity(context, logonName);
        if (yourUser != null)
        {
            if(!yourUser.IsAccountLockedOut())
            {
                yourUser.Enabled = False;
                yourUser.Save();
            }
        }
    }
    

提交回复
热议问题