我正在使用Visual Studio 2015来创建ASP.NET MVC 5应用程序.我正在使用Identity框架在身份验证后向用户添加声明.基于内置添加声明很容易ClaimTypes
,但我遇到了挑战,添加了一个布尔的自定义声明.
我创建了这个静态类来保存我的自定义声明类型:
public static class CustomClaimTypes
{
public static readonly string IsEmployee = "http://example.com/claims/isemployee";
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试向ClaimsIdentity
对象添加自定义声明:
userIdentity.AddClaim(new Claim(CustomClaimTypes.IsEmployee, isEmployee));
Run Code Online (Sandbox Code Playgroud)
它在上面的行中给出了这个错误:
无法转换'bool?' 到'System.Security.Claims.ClaimsIdentity'
我找到的所有例子都是添加字符串.你如何添加bool,int或其他类型?谢谢.