Click to See Complete Forum and Search --> : WindowsPrincipal.IsInRole question


CPCericola
July 23rd, 2002, 01:03 PM
I can't understand why these keeps occuring. The following section of code should output two lines saying true:


WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
Console.WriteLine(MyPrincipal.IsInRole(WindowsBuiltInRole.Administrator));
Console.WriteLine(MyPrincipal.IsInRole("Administrator"));


Instead, the second IsInRole returns false. I've tried domain\username also and I get the same behaviour. I've also created a testgroup and hadded myself to it. Yet again, it fails. Perhaps I'm missing something?

jparsons
July 23rd, 2002, 04:44 PM
Originally posted by CPCericola
I can't understand why these keeps occuring. The following section of code should output two lines saying true:


WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
Console.WriteLine(MyPrincipal.IsInRole(WindowsBuiltInRole.Administrator));
Console.WriteLine(MyPrincipal.IsInRole("Administrator"));


Instead, the second IsInRole returns false. I've tried domain\username also and I get the same behaviour. I've also created a testgroup and hadded myself to it. Yet again, it fails. Perhaps I'm missing something?

I've tried the same thing and I"m getting the same error. It's very baffling.

CPCericola
July 23rd, 2002, 04:46 PM
Originally posted by jparsons


I've tried the same thing and I"m getting the same error. It's very baffling.

I think I figured it out. It's talking about the Domain/Computer role not group. If I'm not mistaken, isn't there a difference between these two?