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(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal principal =
(WindowsPrincipal)Thread.CurrentPrincipal;
return principal.IsInRole(role);
}
F5F5F5 - 07 Jan 2008 13:45 GMT
> if I call the function CurrentUserInRole(@"DOMAIN\NWDeveloper"); it returns
> true, however CurrentUserInRole(@"DOMAIN\IT Development"); it returns false.
In answer to my own problem, the answer appears to be me not quite knowing
what I was doing and being slightly hampered by coincidence.
It appears that I should use the group's Logon Name (pre-Windows 2000)
rather than Name (RDN). In the ones I tried, these had been set-up with to be
the same except the ones I tried with space characters. Although a space
character seems to be perfectly acceptable.