Questions tagged [principalcontext]

PrincipalContext class is part of the Microsoft .NET System Directory Services Account Management API. It encapsulates a server or a domain against which operations are performed. It is also used disambiguate the generic deprecated tag [tag:context].

PrincipalContext class is part of the Microsoft .NET System Directory Services Account Management API. It encapsulates a server or a domain against which operations are performed.

References

See the main documentation of this Class in in the MSDN library.

137 questions
4
votes
1 answer

GroupPrincipal Rename group

I'm trying to rename a group. My code looks like the following PrincipalContext context = new PrincipalContext(ContextType.Machine); GroupPrincipal group = GroupPrincipal.FindByIdentity(context, "GroupName"); group.SamAccountName =…
Sam Stephenson
  • 5,200
  • 5
  • 27
  • 44
4
votes
5 answers

Using UserPrincipal.FindByIdentity and PrincipalContext with nested OU

Here is what I am trying to achieve: I have a nested OU structure that is about 5 levels deep. OU=Portal,OU=Dev,OU=Apps,OU=Grps,OU=Admin,DC=test,DC=com I am trying to find out if the user has permissions/exists at OU=Portal. Here's a snippet of…
XXX
  • 87
  • 1
  • 1
  • 7
3
votes
2 answers

UserPrincipal Security. Disabling unwanted smart card prompt?

I've an application with a logon screen for users to authenticate themselves against the domain. I've made use of the System.DirectoryServices.AccountManagement PrincipalContext/UserPrincipal classes for this. …
Joran Stoops
  • 153
  • 1
  • 13
3
votes
1 answer

How to validate the credentials passed to a `PrincipalContext`

This is a follow up to my previous question. Question What is the correct way of validating the credentials passed to a PrincipalContext? Background In my application I instantiate a PrincipalContext using PrincipalContext(ContextType, String,…
Wes Toleman
  • 311
  • 5
  • 12
3
votes
1 answer

Validate user credentials from Azure AD using PrincipalContext

How can I validate if username and password are valid for Azure AD account using PrincipalContext? I have tried: try { using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "mycompany.com", username, password)) { …
3
votes
2 answers

UserPrincipal with context that uses SSL

I have a PrincipalContext that uses SSL. This works fine when using a method like Context.ValidateCredentials(). But when I need to find a user using UserPrincipal.FindByIdentity() I get the following…
MrProgram
  • 5,044
  • 13
  • 58
  • 98
3
votes
1 answer

C# PrincipalContext The network path was not found

I am trying to use PrincipalContext to check if a local user group exists on a remote computer. I am having problems with PrincipalContext: PrincipalContext ctx = new PrincipalContext(ContextType.Machine, machine, null, ContextOptions.Negotiate) It…
scar80
  • 1,642
  • 2
  • 18
  • 36
3
votes
1 answer

PrincipalContext for query in Active Directory

I want to make a few simple reports from Active Directory. Following discussions, etc. I found that if I use .NET FW 3.5 and up, it is appropriate to use PrincipalContext. I would like to understand principles and what I can do with this new feature…
czWolfHunter
  • 387
  • 2
  • 5
  • 17
2
votes
1 answer

Disconnect Local Windows User Using C#

I have created two test accounts test and test1. I am able to login to one local windows user account "test" using the following code. bool result = false; ContextType contextType = ContextType.Machine; //if (InDomain()) …
azhar rahi
  • 331
  • 4
  • 16
2
votes
3 answers

Accessing user details using Active Directory in an ASP.NET Core MVC app with Windows authentication

I was trying to access user information like first name, last name of the user in my ASP.NET Core MVC project with Windows authentication. I actually make it work after searching for a solution on the web but I am quite new to this stuff and…
2
votes
1 answer

UserPrincipal.DisplayName throws COMException "Access is denied" when running as Azure App Service, working fine on local dev laptop

I've been pulling my hair out at this issue, been all over stack overflow but still haven't been able to fix it. The Goal I am trying to create accounts on demand on Windows Server 2019 Azure VM. The VM is not joined to a domain, just a standalone…
2
votes
0 answers

Getting error while finding AD Groups of a user using PrincipalContext

I have a situation where I need to find AD groups of a user recursively. For Example : I have such group hierarchy - Group1 |_ Group2 |_ Group3 |_ UserA According to the hierarchy, Groups of UserA are…
raunakchoraria
  • 358
  • 2
  • 15
2
votes
1 answer

Testing a `PrincipalContext` using `ValidateCredentials(null, null)` behaves unexpectedly

I need to validate the credentials that are used to connect to an AD server. If if pass invalid credentials to PrincipalContext(ContextType, String, String, String), PrincipalContext.ConnectedServer throws a…
Wes Toleman
  • 311
  • 5
  • 12
2
votes
0 answers

PrincipalContext ValidateCredentials async

I would like to have the PrincipalContext ValidateCredentials method made async. public async Task Login(LoginViewModel model, string returnUrl) { using (PrincipalContext pc = new PrincipalContext(ContextType.Domain,…
J Doe
  • 21
  • 1
2
votes
1 answer

Get the Members of the local group

I am checking weather the user belongs to a particular group. My code is written as follows public static bool IsInGroup(string user, string group) { Console.WriteLine("The user name and group name is {0} {1}", user, group); //Check…
1
2
3
9 10