PrepAway - Latest Free Exam Questions & Answers

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?

PrepAway - Latest Free Exam Questions & Answers

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

5 Comments on “Which code segment should you use?


Leave a Reply