PrepAway - Latest Free Exam Questions & Answers

You develop an ASP.NET MVC application. The application is configured for claims-based authentication by using

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 IC

laimsIdentity 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


Leave a Reply