[英]Role based claims in Identity Server 3 + AspNet Identity
[英]Claims Based Identity
我有一個正在進行的項目。 它使用Thinktecture Identitity Server將令牌傳遞給我的應用程序。 問題是我需要從令牌中提取一個索賠值,到目前為止,我能夠執行Linq查詢以獲取索賠值(我可以通過調試在結果中看到它),但是我無法提取實際值,我嘗試過字符串,toarray等。它一直在給我實際的類型。 我的代碼如下:
var company = ClaimsPrincipal.Current.Identities.ToArray();
var claimType1 = company[0].Claims.ToArray();
var claimtest = from x in claimType1 where x.Type == "http://identityserver.thinktecture.com/claims/profileclaims/company" select x.Value;
String claimfinal = claimtest.ToString();
ViewBag.Message = claimtest.GetType().ToString() + " " + claimfinal;
這是輸出:
System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Security.Claims.Claim,System.String] System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Security.Claims.Claim,System.String]
僅供參考:這僅在控制器中用於測試目的。 理想情況下,我希望能夠處理索賠並將其中的各種信息存儲在單獨的后台類中
claimtest
是一個IEnumerable,您可能只想選擇指定類型的第一個聲明,然后使用其值即可:
var claimtest = claimType1
.First(x => x.Type == "http://identityserver.thinktecture.com/claims/profileclaims/company")
.Value;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.