I use the following function to ascertain if the current user is in ann AD
security group. It appears to work, except if the group contains any space
characters, it always returns false.
For example I am a member of groups "NWDeveloper" and "IT Development"
if I call the function CurrentUserInRole(@"DOMAIN\NWDeveloper"); it returns
true, however CurrentUserInRole(@"DOMAIN\IT Development"); it returns false.
I need to be able to implement role-based security in a WinForm application,
unfortunately I am not in a position to change the security group names.
Thanks in advance.
Alan
----------------------------------------------------------------------------------------------
public static bool CurrentUserInRole(string role)
{
AppDomain.CurrentDomain.SetPrincipalPolicy(Princip alPolicy.WindowsPrincipal);
WindowsPrincipal principal =
(WindowsPrincipal)Thread.CurrentPrincipal;
return principal.IsInRole(role);
}