Different results between declarative and imperative security
- From: "Karin" <karin@xxxxxxxxxxxxx>
- Date: Tue, 19 Sep 2006 04:11:38 GMT
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
.
- Follow-Ups:
- Re: Different results between declarative and imperative security
- From: Joe Kaplan
- Re: Different results between declarative and imperative security
- Prev by Date: Re: Authentication problem
- Next by Date: Re: Authentication problem
- Previous by thread: Authentication problem
- Next by thread: Re: Different results between declarative and imperative security
- Index(es):
Relevant Pages
|
|