Why should we choose PrincipalPermission over IsInRole ()?
Q1 - I'm not sure I understand why we prefer to use PrincipalPermission.Union () (or PrincipalPermission.Intersect ()) instead of IsInRole ()? Anyway, calling IsInRole () multiple times requires less code than creating multiple PrincipalPermission objects and concatenating them into one via Union () (or Intersect ())?
Q2. One overload of the PrincipalPermission object's constructor also specifies the IsAuthenticated flag, which tells Demand () to check if the user is authenticated. Wouldn't you only use this flag in situations where the first two parameters (name and role) are zero?
thanks
a source to share
Q1. - RE: Principled Treatments versus IPrincipal.IsInRole (..)
The two function calls make PrincipalPermission, which has the union or intersection of the roles that you give them. This way you end up with a principal that has a very specific set of requirements, which you can then call IsInRole (). Note that this will lead to your role provider, which could be SQL Server or Active Directory and therefore have latency, so you don't want to do this all the time.
Q2. - RE: Principled Authentication
Authenticated indicates that the user is logged in against your ISP. You might want this if you only want auditing in your application to confirm that the user is logged in to your role provider would mean you can register who they are, etc.
You are right when you say that this is only useful where you are not interested in who the user is, only that they are logged in.
a source to share