2013-08-29 75 views
0

我有一個項目,我正在努力。它使用Thinktecture Identitity Server將令牌傳遞給我的應用程序。問題是我需要從令牌中提取聲明值,到目前爲止,我能夠執行Linq查詢以獲取聲明值(我可以通過調試在結果中看到它),但是我無法將實際值拉出,我試着串起,陣陣等,它一直給我實際的類型。我的代碼如下:基於索賠的身份

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] 

FYI: 這是控制器僅用於測試目的。理想情況下,我希望能夠處理索賠,並將其中的各種信息存儲在單獨的後臺類中

回答

3

claimtest是一個IEnumerable,您可能只想選擇指定類型的第一個索引,然後使用它的值:

var claimtest = claimType1 
    .First(x => x.Type == "http://identityserver.thinktecture.com/claims/profileclaims/company") 
    .Value;   
+0

Darin,那很好,謝謝你 – user60812