get role of user in a string variable
asp.net, c#, role
Solution
You can get a list of groups/roles that a user is part of from the WindowsIdentity.Groups property. The WindowsIdentity.Groups collection only contains the SID's (collection of IdentityReference) of the groups/roles a user is in, but not the actual names of the groups/roles. I will show you how to get the actual names of all the groups/roles a user is in.
First, get the WindowsIdentity object.
WindowsIdentity identity = WindowsIdentity.GetCurrent();
Second, use LINQ to translate the SID's (IdentityReference) to NTAccount's.
var groups = from sid in identity.Groups select sid.Translate(typeof(NTAccount)).Value;
You can then loop through the groups and store them in a string array that can be used in the FormsAuthenticationTicket. This will get you both the BUILTIN (local computer) groups/roles and also DOMAIN groups/roles the user is in.
Problem
is there a way i can get the role in a string variable using the below commands.... ``` System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal wp = new System.Security.Principal.WindowsPrincipal(wi); ``` i need this for ``` FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version UserName.Text, // user name DateTime.Now, // creation DateTime.Now.AddMinutes(60),// Expiration false, // Persistent role); // User data ``` as string role= wp.IsInRole(); but this is not right something similar to this...