Condividi tramite


Ricerca di attestazioni in ClaimSet

L'analisi del contenuto di un ClaimSet per particolari tipi di attestazioni è un'attività comune quando si utilizza l'autorizzazione basata su attestazioni. Per esaminare un ClaimSet per la presenza di attestazioni specifiche, usare il metodo FindClaims. Questo metodo offre prestazioni migliori rispetto all'iterazione diretta su ClaimSet. Nell'esempio seguente viene illustrato questo utilizzo. Si noti che i claimType parametri e claimRight possono essere null. In tal caso, i parametri corrisponderanno a tutti i tipi di diritto e ai diritti di rivendicazione.

Esempio

// The FindSomeClaims method looks in the provided ClaimSet for Claims of the specified type and right.
// It returns such Claims in a list.
public static IList<Claim> FindSomeClaims ( ClaimSet cs, string type, string right )
{
  // Create an empty list
  IList<Claim> claims = new List<Claim>();

  // Call ClaimSet.FindClaims with the specified type and right. Iterate over the result...
  foreach(Claim c in cs.FindClaims ( type, right ))
    //...adding each claim to the list
    claims.Add ( c );

  // Return the list
  return claims;
}
' The FindSomeClaims method looks in the provided ClaimSet for Claims of the specified type and right. 
' It returns such Claims in a list.
Public Shared Function FindSomeClaims(ByVal cs As ClaimSet, _
                                      ByVal type As String, _
                                      ByVal right As String) As IList(Of Claim)
    ' Create an empty list
    Dim claims As New List(Of Claim)()

    ' Call ClaimSet.FindClaims with the specified type and right. Iterate over the result...
    For Each c In cs.FindClaims(type, right)
        '...adding each claim to the list
        claims.Add(c)
    Next c

    ' Return the list
    Return claims
End Function

Vedere anche