How can I retrieve all the roles (groups) a user is a member of?

WindowsPrincipal.IsInRole just checks if the user is a member of the group with that name; a Windows Group is a Role. You can get a list of the groups that a user is a member of from the WindowsIdentity.Groups property. You can get WindowsIdentity from your WindowsPrincipal: WindowsIdentity identity = WindowsPrincipal.Identity as WindowsIdentity; or you … Read more

How do I perform WIF/claims impersonation without the claim being mapped to an AD account?

I spent several months working on trying to solve this problem and after spending a long time working with Microsoft SharePoint and WIF engineers came to the conclusion that this is not possible. It appears that the issue is basically what Kirk alludes to. When creating an impersonated session using Claims (e.g. creating an SPClaim … Read more

How do I get the currently-logged username from a Windows service in .NET?

This is a WMI query to get the user name: ManagementObjectSearcher searcher = new ManagementObjectSearcher(“SELECT UserName FROM Win32_ComputerSystem”); ManagementObjectCollection collection = searcher.Get(); string username = (string)collection.Cast<ManagementBaseObject>().First()[“UserName”]; You will need to add System.Management under References manually.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)