exam questions

Exam 70-486 All Questions

View all questions & answers for the 70-486 exam

Exam 70-486 topic 1 question 91 discussion

Actual exam question from Microsoft's 70-486
Question #: 91
Topic #: 1
[All 70-486 Questions]

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;
Show Suggested Answer Hide Answer
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

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
hungry_ape9000
Highly Voted 5 years, 1 month ago
FINAL ANSWER: B is correct Don't forget null checks though, potential null exceptions or out of range exceptions too.
upvoted 7 times
...
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.

SaveCancel
Loading ...