I was testing PrincipalPermission functionality and there are some things I don't understand.
Can anyone tell me what's wrong with this code? I'm trying to disallow some methods to users with role "thief" or to users that are not anonymous. Here's the code:
[PrincipalPermission(SecurityAction.Deny, Role="Thief")]
private void MethodNotForThiefs()
{ }
[PrincipalPermission(SecurityAction.Demand, Authenticated=false)]
private void MethodOnlyForAnonyms()
{ }
private void button46_Click(object sender, EventArgs e)
{
GenericIdentity gi = new GenericIdentity("User");
string[] roles = {"Thief"};
GenericPrincipal gp = new GenericPrincipal(gi, roles);
Thread.CurrentPrincipal = gp;
MethodNotForThiefs();
MethodOnlyForAnonyms();
}