Different results between declarative and imperative security



Hi,

Can anyone tell me why I get two different results with the following 2 ways
of checking to see if I'm in the Administrators group? This is in a Windows
form in C#:
If I comment out the first line (the PrincipalPermissionAttribute line),
then I get the message that I am an Administrator. Yet, when I uncomment the
declarative security attribute then I get the error message: "Request for
principal permission failed".

Seems like since I am in the local administrator's group that I should be
allowed to access the class.

[PrincipalPermission(SecurityAction.Demand, Role="Administrators")]
public class Security_Test : System.Windows.Forms.Form
{
/*
... Initialize Component stuff and Constructor removed for brevity
*/

private void Security_Test_Load(object sender, System.EventArgs e)
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal prin = (WindowsPrincipal)
System.Threading.Thread.CurrentPrincipal;
bool fAdmin = prin.IsInRole(WindowsBuiltInRole.Administrator);
if(fAdmin)
{
MessageBox.Show(
"You are a member of the Administrators group");
}
}
}
}

Thanks,
Karin


.



Relevant Pages

  • Re: administrator unable to logon interactively
    ... All domain clients and workstations run the Windows XP ... domain controller and the secondary domain controller. ... >> administrators group including the administrator can ...
    (microsoft.public.win2000.security)
  • Re: administrator on box also on domain?
    ... > administrators group at the PC then it shows something like: ... > domain_name\Domain Admins ... so we add the user to the local Administrators ...
    (microsoft.public.windows.server.active_directory)
  • Re: User rights
    ... This issue is with SBS automatically pulling the local user account into ... Will it still migrate that user up to SBS? ... are automatically Sharepoint Administrators. ... > to remove the Power Users group from the Sharepoint Administrators group. ...
    (microsoft.public.windows.server.sbs)
  • Odd behaviour with user accounts (accounts "hidden")
    ... installation), dad and kids. ... "Administrators" group. ... As soon as I remove "kids" from the administrators group the account ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Confused
    ... Administrators group so they are administrators of the child domain, ... By default the Domain Admins of a domain are member of the ...
    (microsoft.public.win2000.active_directory)