Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

WindowsPrincipal.IsInRole fails when there is Whitespace in role n

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
F5F5F5 - 04 Jan 2008 17:41 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.