2013-08-29 47 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