locked
How to access a specific claim in claim aware application RRS feed

  • Question

  • User1315728448 posted

    Hello I ahave a claim aware application and i am using sts to send the claims.

    currently i am accessing the claims as

    Identity.Claims[5].Value
    
    but i want to access a perticular claim and dont want to access it by the position.
    I want to access it something like this

    Identity.Claims["UserName"].Value.

    Does anybody know how to do it.

    please help me to find the proper solution.
    Friday, August 17, 2012 2:48 AM

Answers

  • User1779161005 posted

    Use LINQ:

    var nameClaimQuery =

         from c in Identity.Claims

        where c.ClaimType == ClaimsTypes.Name

        select c;

    var nameClaim = nameClaimQuery.FirstOrDefault();

    if (nameClaim != null) var name = nameClaim.Value;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 17, 2012 10:48 AM