directoryservices

Why would this catch all block not in fact catch all

二次信任 提交于 2019-12-04 05:06:34
The code is fairly simple --- the issue is that there is an invalid character in the groupPath string (a '/' to be exact). What I'm trying to do (at least as a stop gap) is skip over DirectoryEntries that I can't get the cn for --- regardless of why. However when I run this code the catch block doesn't run and I get instead: The server is not operational. and an unhandled System.Runtime.InteropServices.COMException. Why would the catch block not catch this exception. try { using (DirectoryEntry groupBinding = new DirectoryEntry("LDAP://" + groupPath)) { using (DirectorySearcher groupSearch =

DirectoryServices UserPrincipal.SetPassword ignores password policy (password history)

假如想象 提交于 2019-12-04 04:16:43
问题 As the title suggests, I am having an issue regarding respecting the password policy when setting a users password, specifically, the password history restriction. The scenario is a user password reset, when the user does not know his current password. I am using the following to accomplish this: using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "XXXX", "ADMINUSER", "ADMINPASSWORD")) { using (UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType

How to search Global Catalog (whole forest) using PrincipalContext

柔情痞子 提交于 2019-12-04 02:06:25
问题 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); } }

“Access Denied” when trying to connect to remote IIS server - C#

[亡魂溺海] 提交于 2019-12-03 22:12:59
I receive an "Access Deined" COMException when I try to connect to a remote IIS 6 server from my C# application that is running under IIS 5.1. Any ideas? I am experiencing all the same issues with the original questions. Update - 4/1/09 I found this solution ( http://www.codeproject.com/KB/cs/Start_Stop_IIS_Website.aspx ) that consists of a window application connecting to an IIS server to start and stop web sites. I am able to run it on my workstation and connect to the IIS server. Ugh....why can I run this stand alone application but not my ASP.NET application? Original I receive an "Access

How to determine all the groups a user belongs to (including nested groups) in ActiveDirectory and .NET 3.5

喜你入骨 提交于 2019-12-03 18:47:14
问题 I have an application that uses ActiveDirecotry authorisation and it has been decided that it needs to support nested AD groups, e.g.: MAIN_AD_GROUP | |-> SUB_GROUP | |-> User So, the user in not directly a member of MAIN_AD_GROUP . I'd like to be able to look for the user recursively, searching the groups nested in MAIN_AD_GROUP . The main problem is that I'm using .NET 3.5 and there is a bug in System.DirectoryServices.AccountManagement in .NET 3.5 whereby the method UserPrincipal

UserPrincipal.FindByIdentity throws exception - There is no such object on the server

倖福魔咒の 提交于 2019-12-03 16:59:56
I'm struggling with a simple scenario: I would like to retrieve my account from Active Directory using the username and password which I use to log into my computer. My first issue was that I was receiving a referral from the server when attempting to call UserPrincipal.FindByIdentity. I thought that this was a bit weird, given the fact that PrincipalContext.ValidateCredentials was working fine, but it turns out that my DC path was incorrect. I wasn't sure how to properly craft my OU/DC string. As such, I found this SO post which helpful provided the following bit of code: private static

Intermittent unknown error from Active Directory

六眼飞鱼酱① 提交于 2019-12-03 15:59:10
I'm using .Net account management libraries to access Active Directory to search the details of current http request user. My app pool runs with custom account and it also from the same domain. Server and users also belong to same domain. public string GetEmployeeId(string SAMAccountName) { using (PrincipalContext domainContext = new PrincipalContext(ContextType.Domain)) { using (UserPrincipal userprincipal = new UserPrincipal(domainContext)) { userprincipal.SamAccountName = SAMAccountName; using (PrincipalSearcher ps = new PrincipalSearcher()) { ps.QueryFilter = userprincipal; UserPrincipal

How to retrieve SAMAccountName from Active Directory

霸气de小男生 提交于 2019-12-03 14:39:38
I implemented a method that returns a list of Active Directory users, I would like to retrieve SAMAccountName like this Domain\Administrator . This is the method I use: public Collection<software_user> GetUsersFromAD(String adConnectionString) { var users = new Collection<software_user>(); using (var directoryEntry = new DirectoryEntry(adConnectionString)) { var directorySearcher = new DirectorySearcher(directoryEntry); directorySearcher.Filter = "(&(objectClass=user))"; var propertiesToLoad = new[] { "SAMAccountName", "displayName", "givenName", "sn", "mail", "userAccountControl", "objectSid"

How do I use BER encoding with object System.DirectoryServices.Protocols.BerConverter.Encode(“???”, myData)

空扰寡人 提交于 2019-12-03 10:03:51
I need to encode and decode BER data. .NET has the class System.DirectoryServices.Protocols.BerConverter The static method requires me to enter a string in the first parameter as shown below byte[] oid = { 0x30, 0xD, 0x6, 0x9, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0xD, 0x1, 0x1, 0x1, 0x5, 0x0 }; // Object ID for RSA var result2 = System.DirectoryServices.Protocols.BerConverter.Decoding("?what goes here?", oid); BER encoding is used in LDAP, Certificates, and is commonplace in many other formats. I'll be happy with information telling me how to Encode or Decode on this class. There is nothing on Stack

How to list all computers and the last time they were logged onto in AD?

大城市里の小女人 提交于 2019-12-03 09:42:36
I am trying to retrieve a list of Computer Names and the date they were last logged onto from Active Directory and return them in a datatable. Getting the names is easy enough but when I try to add the "lastLogon" or "lastLogonTimestamp" like shown below, the only values I get for the lastLogonTimestamp is "System._ComObject" public DataTable GetListOfComputers(string domainName) { DirectoryEntry entry = new DirectoryEntry("LDAP://DC=" + domainName + ",DC=com"); DirectorySearcher search = new DirectorySearcher(entry); string query = "(objectclass=computer)"; search.Filter = query; search