天道酬勤,学无止境

directoryservices

How to set connection time out when establishing context - PrincipalContext

问题 using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Domain, UserName, Password)) { UserPrincipal U = new UserPrincipal(ctx); U.GivenName = strFirstName; U.Surname = strLastName; U.EmailAddress = strEmail; PrincipalSearcher srch = new PrincipalSearcher(U); foreach (var principal in srch.FindAll()) { var p = (UserPrincipal)principal; if (!User.Any(x => x.Email == p.EmailAddress)) { MyUserDataset.UserRow User = User.NewUserRow(); User.FirstName = p.GivenName; User.LastName = p.Surname; User.UserName = p.SamAccountName; User.Email = p.EmailAddress; User.AddUserRow(User); } }

2022-05-10 10:42:14    分类:技术分享    c#   c#-4.0   directoryservices   adsi   principalcontext

How to set connection time out when establishing context - PrincipalContext

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Domain, UserName, Password)) { UserPrincipal U = new UserPrincipal(ctx); U.GivenName = strFirstName; U.Surname = strLastName; U.EmailAddress = strEmail; PrincipalSearcher srch = new PrincipalSearcher(U); foreach (var principal in srch.FindAll()) { var p = (UserPrincipal)principal; if (!User.Any(x => x.Email == p.EmailAddress)) { MyUserDataset.UserRow User = User.NewUserRow(); User.FirstName = p.GivenName; User.LastName = p.Surname; User.UserName = p.SamAccountName; User.Email = p.EmailAddress; User.AddUserRow(User); } }

2022-04-27 05:37:41    分类:问答    c#   c#-4.0   directoryservices   adsi   principalcontext

How to search Global Catalog (whole forest) using PrincipalContext

问题 myUserList AppUsers = new myUserList(); using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, domainName)) { UserPrincipal User = new UserPrincipal(pcxt); User.EmailAddress = emailString; PrincipalSearcher srch = new PrincipalSearcher(User); foreach (var principal in srch.FindAll()) { var p = (UserPrincipal)principal; myUserRow User = AppUsers.NewUsersRow(); User.FirstName = p.GivenName; User.LastName = p.Surname; User.Email = p.EmailAddress; AppUsers.AddUsersRow(User); } } 我有类似于上面的代码,它使用 PrincipalContext 类在 Active Directory 中搜索用户信息。 如您所见,我在搜索过程中传入了域名。

2022-04-26 09:21:14    分类:技术分享    c#   active-directory   directoryservices   directoryentry   account-management

Active Directory move a user to a different OU

问题 我正在开发一个程序,该程序将为离开我们网络的用户自动化分离过程。 它执行的任务之一是将用户帐户从它所在的 OU 移动到Former Employees OU。 即使我在使用DirectoryServices执行其他进程时没有任何问题,但我在这一步中一直遇到问题。 到目前为止,这是我的代码(注意:我知道我需要停止捕获和吃掉所有异常。这将在发布前得到解决和纠正。关于我应该捕获哪些异常以及我不应该感谢的任何建议): private const string AD_DOMAIN_NAME = "domain.com"; private const string AD_NEW_PASSWORD = "TestPassword123"; private const string AD_FORMER_EMPLOYEES_OU = "LDAP://OU=Former Employees,DC=domain,DC=com"; static DirectoryEntry CreateDirectoryEntry(string connectionPath, string adUserName, string adPassword) { DirectoryEntry ldapConnection = null; try { ldapConnection = new DirectoryEntry

2022-04-21 00:49:12    分类:技术分享    c#   active-directory   directoryservices

Error with Directory.Services when on production

The following code works fine in Visual Studio Development enviroment on my local machine. However when I move the files to a Windows 2008 R2 IIS 7.5 machine I get the following error: [DirectoryServicesCOMException (0x80072020): An operations error occurred. ] _Default.GetFullName(String strLoginName, String& STR_FIRST_NAME, String& STR_LAST_NAME, String& STR_DISPLAY_NAME, String& STR_MAIL, String& STR_OFFICE_PHONE, String& STR_ADDRESS) in c:\AuthTest\Default.aspx.cs:87 _Default.Page_Load(Object sender, EventArgs e) in c:\AuthTest\Default.aspx.cs:23 System.Web.Util.CalliHelper

2022-04-17 05:12:05    分类:问答    c#   asp.net   active-directory   directoryservices

Active Directory move a user to a different OU

I'm working on a program that will automate the separation process for users leaving our network. One of the tasks it performs is moving the user account from the OU it is in, to a Former Employees OU. I've been having problems with this step even though I've not had any issues doing other processes with DirectoryServices. Here's my code thus far (note: I know I need to stop catching and eating all exceptions. This will be addressed and corrected before release. Any advice on which exceptions I should catch and which I should not would be appreciated too): private const string AD_DOMAIN_NAME =

2022-04-17 01:57:45    分类:问答    c#   active-directory   directoryservices

Looking for a Full S.DS.AM Sample with many AD extensions already written

System.DirectoryServices.AccountManagement can be extended to support additional properties for reading and writing AD properties. Is anyone aware of a full/complete sample implementation that works for AD, Exchange 2003 or 2010?

2022-04-16 16:21:31    分类:问答    directoryservices   account-management   userprincipal

UserPrincipal.GetGroups fails with unknown error

I am trying to get all Active Directory groups for a user, with the following code: private static IEnumerable<string> GetGroupNames(string userName) { using (var context = new PrincipalContext(ContextType.Domain)) { using (var userPrincipal = UserPrincipal.FindByIdentity(context, userName)) { var groupSearch = userPrincipal.GetGroups(context); var result = new List<string>(); foreach (var principal in groupSearch) { Log.LogDebug("User {0} is member of group {0}", userPrincipal.DisplayName, principal.DisplayName); result.Add(principal.SamAccountName); } return result; } } } This code correctly

2022-04-05 04:55:51    分类:问答    .net   active-directory   directoryservices

How to search Global Catalog (whole forest) using PrincipalContext

myUserList AppUsers = new myUserList(); using (PrincipalContext pcxt = new PrincipalContext(ContextType.Domain, domainName)) { UserPrincipal User = new UserPrincipal(pcxt); User.EmailAddress = emailString; PrincipalSearcher srch = new PrincipalSearcher(User); foreach (var principal in srch.FindAll()) { var p = (UserPrincipal)principal; myUserRow User = AppUsers.NewUsersRow(); User.FirstName = p.GivenName; User.LastName = p.Surname; User.Email = p.EmailAddress; AppUsers.AddUsersRow(User); } } I have code similar to the above that searches Active Directory for user information using

2022-04-03 22:36:27    分类:问答    c#   active-directory   directoryservices   directoryentry   account-management