Question: Subject: C# .NET You are developing a program that needs to find out the identity of the logged-in Windows user and the name of the

Subject: C# .NET

You are developing a program that needs to find out the identity of the logged-in Windows user and the name of the Windows Groups that the user is a member of. How would you write a program to retrieve this information?

This is what I have so far... getting error with last line of code "return user.isMemberOf(groups);" It's giving error "Argument 1: Cannot convert from PrincipalSearchResult to System.DirectoryServices.AccountManagement.GroupPrincipal."

class Program { static void Main(string[] args) { string username; username = WindowsIdentity.GetCurrent().Name;

PrincipalContext context = new PrincipalContext(ContextType.Domain, "Domain");

//Find user UserPrincipal user = UserPrincipal.FindByIdentity(context, username);

//Find groups PrincipalSearchResult groups = UserPrincipal.Current.GetGroups(); IEnumerable groupnames = groups.Select(x => x.SamAccountName);

if(user != null) { return user.IsMemberOf(groups); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!