I currently have two roles like this:
[PrincipalPermission(SecurityAction.Demand, Role="Domain\Admin")] [PrincipalPermission(SecurityAction.Demand, Role="Domain\AnotherRole")]
The problem is that this inherited code is specific to the domain, and I want to eventually get the roles from the web.config file, so I can work on a VM not in the domain.
I have seen an example like this:
PrincipalPermission permCheck = new PrincipalPermission( null, @"Domain\Admin"); permCheck.Demand();
Since this throws an exception if user is not in role, how do I change this example to allow either of the two roles? I could use multiple IPrincipal.IsInRole() and then throw my own exception, but seems like there is probably a way to use the .Demand method with multiple roles.
Update 12/21: Sample Code based on Union link from Ladislav's answer below:
PrincipalPermission ppAdmin = new PrincipalPermission(null, @"Domain\Admin");
PrincipalPermission ppAnother = new PrincipalPermission(null, @"Domain\AnotherRole");
(ppAdmin.Union(ppAnother)).Demand();
But AzMan (suggested by Ladislav looks like a better but more involved solution).