gpt4 book ai didi

c# - 列出 C# 中 System.Security.Claims.ClaimTypes 中存储的所有声明类型

转载 作者:行者123 更新时间:2023-12-02 03:28:37 25 4
gpt4 key购买 nike

使用 Asp.Net Identity 允许您向用户添加声明。 System.Security.Claims.ClaimTypes 允许您从各种 ClaimType 中选择任何 ClaimType。

ClaimTypes 是一个静态类,定义可分配给主题的众所周知的声明类型的常量。

我想将所有这些声明存储在 List<> 中,并将它们显示在 ListBox 中,以便具有 Admin 角色的用户可以在注册后为用户分配 ClaimType。

似乎我可以做到这一点,因为 ClaimTypes 是一个静态类,并且无法列出其中定义的那些常量。

最佳答案

您可以通过反射(reflect)类中的字段来列出声明类型:

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

对于列表中的每个 claimType,您可以使用 claimType.Name 获取常量名称,并使用 claimType.GetValue(null) 获取得到常数值。

关于c# - 列出 C# 中 System.Security.Claims.ClaimTypes 中存储的所有声明类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52484869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com