Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all the Claim types stored in the System.Security.Claims.ClaimTypes in C#

Working with Asp.Net Identity allow you to add the claims to a user. And the System.Security.Claims.ClaimTypes allows you to select any ClaimType from various ClaimTypes.

ClaimTypes is a static class and defines constants for well-known claim types that can be assigned to subjects.

I want to store all these claims in a List<> and display them in a ListBox so that the user with the Admin role can assign a ClaimType to a user after registration.

Seems that I can do that as ClaimTypes is a static class and those constants defined in that can't be listed.

like image 246
Junaid Sultan Avatar asked Dec 21 '25 03:12

Junaid Sultan


1 Answers

You can list out the claim types by reflecting on the fields in the class:

var claimTypes = typeof(System.Security.Claims.ClaimTypes).GetFields().ToList();

For each claimType in the list, you can use claimType.Name to get the constant name and claimType.GetValue(null) to get the constant value.

like image 62
Travis Schettler Avatar answered Dec 23 '25 15:12

Travis Schettler