![](/img/trans.png)
[英]error CS0117: `System.Security.Claims.ClaimTypes' does not contain a definition for `Role'
[英]List all the Claim types stored in the System.Security.Claims.ClaimTypes in C#
使用Asp.Net Identity允許您將聲明添加到用戶。 System.Security.Claims.ClaimTypes允許您從各種ClaimTypes中選擇任何ClaimType。
ClaimTypes是一個靜態類,它定義了可以分配給主題的眾所周知的聲明類型的常量。
我想將所有這些聲明存儲在List <>中並將它們顯示在ListBox中,以便具有Admin角色的用戶可以在注冊后為用戶分配ClaimType。
似乎我可以這樣做,因為ClaimTypes是一個靜態類,並且無法列出那些定義的常量。
您可以通過反映類中的字段來列出聲明類型:
var claimTypes = typeof(System.Security.Claims.ClaimTypes).GetFields().ToList();
對於列表中的每個claimType
,您可以使用claimType.Name
獲取常量名稱,使用claimType.GetValue(null)
來獲取常量值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.