Created
April 9, 2018 02:15
-
-
Save rbrayb/99b4b45e21c01c0eefe70c1da6651819 to your computer and use it in GitHub Desktop.
Displaying claims in an ASP.NET MVC application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@*Replace existing code with ...*@ | |
@{ | |
ViewBag.Title = "User Claims"; | |
} | |
<h2>Welcome: @ViewBag.ClaimsIdentity.Name</h2> | |
<h3>Values from Identity</h3> | |
<table> | |
<tr> | |
<th> | |
IsAuthenticated | |
</th> | |
<td> | |
@ViewBag.ClaimsIdentity.IsAuthenticated | |
</td> | |
</tr> | |
<tr> | |
<th> | |
Name | |
</th> | |
<td> | |
@ViewBag.ClaimsIdentity.Name | |
</td> | |
</tr> | |
</table> | |
<h3>Claims from ClaimsIdentity</h3> | |
<table class="table table-bordered table-striped"> | |
<tr> | |
<th> | |
Claim Type | |
</th> | |
<th> | |
Claim Value | |
</th> | |
@*<th> | |
Value Type | |
</th> | |
<th> | |
Subject Name | |
</th> | |
<th> | |
Issuer Name | |
</th>*@ | |
</tr> | |
@foreach (System.Security.Claims.Claim claim in ViewBag.ClaimsIdentity.Claims) | |
{ | |
<tr> | |
<td> | |
@claim.Type | |
</td> | |
<td> | |
@claim.Value | |
</td> | |
@*<td> | |
@claim.ValueType | |
</td> | |
<td> | |
@claim.Subject.Name | |
</td> | |
<td> | |
@claim.Issuer | |
</td>*@ | |
</tr> | |
} | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change Contact() to: | |
public ActionResult Contact() | |
{ | |
ViewBag.Message = "Your contact page."; | |
ViewBag.ClaimsIdentity = Thread.CurrentPrincipal.Identity; | |
return View(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment