Which code segment should you use?

You develop an ASP.NET MVC application. The application is configured for claims-based authentication by
using Windows Identity Foundation (WIF).
You need to access the claims in the WIF token.
Which code segment should you use?

You develop an ASP.NET MVC application. The application is configured for claims-based authentication by
using Windows Identity Foundation (WIF).
You need to access the claims in the WIF token.
Which code segment should you use?

A.
Thread.CurrentPrincipal.Identity;

B.
((IClaimsPrincipal)Thread.CurrentPrincipal).Identities[0].Claims;

C.
Thread.CurrentPrincipal;

D.
((IClaimsPrincipal)Thread.CurrentPrincipal).Identities[0].IsAuthenticated;

Explanation:
To Access the Claims
In order to access identity related information, you can run FedUtil. Once you have run FedUtil, your application
can access IClaimsPrincipal and IClaimsIdentity using the standard ASP.NET constructs as shown in the
following code example:
void Page_Load(object sender, EventArgs e)
{
// Cast the Thread.CurrentPrincipal
IClaimsPrincipal icp = Thread.CurrentPrincipal as IClaimsPrincipal;
// Access IClaimsIdentity which contains claims
IClaimsIdentity claimsIdentity = (IClaimsIdentity)icp.Identity;
// Access claims
foreach(Claim claim in claimsIdentity.Claims)
{ }}
https://msdn.microsoft.com/en-us/library/ee517271.aspx



Leave a Reply 3

Your email address will not be published. Required fields are marked *


nope

nope

According to the given link in the answer, I think it’s A.

DQ

DQ

I think the answer should be ((IClaimsPrincipal)Thread.CurrentPrincipal).Identity.Claims[0]

Sinan Uysal

Sinan Uysal

The answers is wrong. DQ is right