找出用户属于哪个组

我有一个Windows用户帐户,我刚刚创build以XYZ为例。

此XYZ属于用户组和我在计算机pipe理 – >本地用户和组中创build的自定义组。

所以在属性我看到用户属于2组。

现在我想要得到这些组并显示它们。 有什么build议么?

我已经这样做了,但这是不正确的,因为它给了我SQL的angular色(我认为)

这是我做的:

login和模拟后,我调用该函数

getUserGroups(); private void getUserGroups() { // collect the user domain and identity string[] arr = System.Web.HttpContext.Current.Request. LogonUserIdentity.Name.Split('\\'); // update the display to show // the captured domain and user if (arr.Length > 0) { new GUIUtility().LogMessageToFile("User Name" + arr[0].ToString()); new GUIUtility().LogMessageToFile("User Domain" + arr[1].ToString()); } // create an arraylist and populate // it with the list of groups that // the current user belongs to ArrayList al = new ArrayList(); al = GetGroups(); // check to see if the user belongs // to a specific group and create // a list of all of the user's groups foreach (string s in al) { // add this one to the list new GUIUtility().LogMessageToFile("Group" + s); // check to see if the user // belongs to a specific group //if (s == "BXSWLT\\SomeCustomGroup") //{ // // change the label to show // // there was a match // lblMemberOfGroup.Text = "YES"; //} } } public ArrayList GetGroups() { ArrayList groups = new ArrayList(); foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups) { groups.Add(group.Translate(typeof (System.Security.Principal.NTAccount)).ToString()); } return groups; } 

我得到的结果是:

 9/8/2010 5:57:22 PM: User Name NT AUTHORITY. 9/8/2010 5:57:22 PM: User Domain IUSR. 9/8/2010 5:57:22 PM: Group Everyone. 9/8/2010 5:57:22 PM: Group BUILTIN\Users. 9/8/2010 5:57:22 PM: Group NT AUTHORITY\Authenticated Users. 9/8/2010 5:57:22 PM: Group NT AUTHORITY\This Organization. 9/8/2010 5:57:22 PM: Group LOCAL. 

Solutions Collecting From Web of "找出用户属于哪个组"