directoryservices

Error with UserPrincipal.GetAuthorizationGroups() method

怎甘沉沦 提交于 2019-12-03 07:26:12
I am having an issue using the GetAuthorizationGroups method of the UserPrincipal class in a web application. Using the following code, I am receiving "While trying to retrieve the authorization groups, an error (5) occurred" PrincipalContext context = new PrincipalContext(ContextType.Domain, null, "DC=MyCompany,DC=COM", "username", "password"); UserPrincipal p = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "joe.blogs"); var groups = p.GetAuthorizationGroups(); I believe this code works to an extent. When I view the context object, I can see the server and username

How to get the NETBIOS Domain Name using the FQDN in a Complex Environment

别说谁变了你拦得住时间么 提交于 2019-12-03 07:17:07
问题 Getting the NETBIOS domain name from a fully qualified Active Directory domain name is sometimes a tedious task. I found a good answer here. In an environment with multiple forests this approach will however not work if the PC is not in the forest you are querying. This is because LDAP://RootDSE will query information for the computer’s domain. Some might ask: why so complicated? Just use the name before the first dot retrieved by: ActiveDirectory.Domain.GetComputerDomain().Name; Or just get

System.DirectoryServices is not recognised in the namespace 'System'

廉价感情. 提交于 2019-12-03 01:09:22
I'm trying to use System.DirectoryServices in a web site project and I'm getting this error: The type or namespace name 'DirectoryServices' does not exist in the namespace 'System' (are you missing an assembly reference?) My project has a reference to System.DirectoryServices in web.config : <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> And I do have using System.DirectoryServices in the files where I want to use it. Does anybody have a clue where to look for the problem? Is the web-server (IIS or whatever) configured to run the

How to get the NETBIOS Domain Name using the FQDN in a Complex Environment

南楼画角 提交于 2019-12-02 20:50:55
Getting the NETBIOS domain name from a fully qualified Active Directory domain name is sometimes a tedious task. I found a good answer here . In an environment with multiple forests this approach will however not work if the PC is not in the forest you are querying. This is because LDAP://RootDSE will query information for the computer’s domain. Some might ask: why so complicated? Just use the name before the first dot retrieved by: ActiveDirectory.Domain.GetComputerDomain().Name; Or just get the user's domain name: Environment.GetEnvironmentVariable("USERDOMAIN"); or Environment

Create an application pool that uses .NET 4.0

最后都变了- 提交于 2019-12-02 20:18:29
I use the following code to create a app pool: var metabasePath = string.Format(@"IIS://{0}/W3SVC/AppPools", serverName); DirectoryEntry newpool; DirectoryEntry apppools = new DirectoryEntry(metabasePath); newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool"); newpool.CommitChanges(); How do I specify that the app pool should use .NET Framework 4.0? I see from the tags you're using IIS7. Unless you absolutely have to, don't use the IIS6 compatibility components. Your preferred approach should be to use the Microsoft.Web.Administration managed API. To create an application pool

Difference between PrincipalSearcher and DirectorySearcher

你。 提交于 2019-12-02 14:18:27
I see Active Directory examples that use PrincipalSearcher and other examples that do the same thing but use DirectorySearcher . What is the difference between these two examples? Example using PrincipalSearcher PrincipalContext context = new PrincipalContext(ContextType.Domain); PrincipalSearcher search = new PrincipalSearcher(new UserPrincipal(context)); foreach( UserPrincipal user in search.FindAll() ) { if( null != user ) Console.WriteLine(user.DistinguishedName); } Example using DirectorySearcher DirectorySearcher search = new DirectorySearcher("(&(objectClass=user)(objectCategory=person)

Limiting the attributes returned in an LDAP query

故事扮演 提交于 2019-12-02 11:29:06
How do I limit the attributes that are returned in an LDAP query through System.DirectoryServices? I have been using a DirectorySearcher and adding the properties that I want to DirectorySearcher.PropertiesToLoad. The problem is that this just makes sure that the added properties are included in the DirectoryEntry.Properties as well as some default list. Is there any way to specify the only properties that you want returned? DirectoryEntry base = new DiectoryEntry(rootPath, null, null, AuthenticationTypes.FastBind); DirectorySearcher groupSearcher = new DirectorySearcher(base); groupSearcher

Problems with Directory Services and Account Management in ASP.NET Core

孤者浪人 提交于 2019-12-01 18:35:24
I have a ASP.NET Core API project and I'd like to utilize DirectoryServices and DirectoryServices.AccountManagement namespaces. After some research I thought I found some project.json references that would work: { "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "dependencies": { "EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer.Design": "7.0.0-rc1-final", "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", "Microsoft.AspNet.Server

How to change System.DirectoryEntry “uSNChanged” attribute value to an Int64

烈酒焚心 提交于 2019-12-01 17:37:06
I'm trying to get the Int64 value of a Directory Services object's "uSNChanged" value. Unfortunately, it is always coming back as a COM object of some kind. I've tried using casting to Int64, calling Int64.Parse(), and calling Convert.ToInt64(). None of these work. For a given DirectoryEntry object, this code will display the properties: private static void DisplaySelectedProperties(DirectoryEntry objADObject) { try { string[] properties = new string[] { "displayName", "whenCreated", "whenChanged", "uSNCreated", "uSNChanged", }; Console.WriteLine(String.Format("Displaying selected properties

How to change System.DirectoryEntry “uSNChanged” attribute value to an Int64

旧时模样 提交于 2019-12-01 16:28:35
问题 I'm trying to get the Int64 value of a Directory Services object's "uSNChanged" value. Unfortunately, it is always coming back as a COM object of some kind. I've tried using casting to Int64, calling Int64.Parse(), and calling Convert.ToInt64(). None of these work. For a given DirectoryEntry object, this code will display the properties: private static void DisplaySelectedProperties(DirectoryEntry objADObject) { try { string[] properties = new string[] { "displayName", "whenCreated",