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;
Suggested Answer:B🗳️
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) { . . . } } References: https://msdn.microsoft.com/en-us/library/ee517271.aspx
FINAL ANSWER: B is correct
Don't forget null checks though, potential null exceptions or out of range exceptions too.
upvoted 7 times
...
This section is not available anymore. Please use the main Exam Page.70-486 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
hungry_ape9000
Highly Voted 5 years, 1 month ago