【发布时间】:2017-06-21 13:38:13
【问题描述】:
我正在使用 Visual Studio 2015 创建一个 ASP.NET MVC 5 应用程序。我正在使用身份框架在身份验证后向用户添加声明。基于内置 ClaimTypes 添加声明很容易,但我在添加布尔的自定义声明时遇到了挑战。
我创建了这个静态类来保存我的自定义声明类型:
public static class CustomClaimTypes
{
public static readonly string IsEmployee = "http://example.com/claims/isemployee";
}
然后我尝试向ClaimsIdentity 对象添加自定义声明:
userIdentity.AddClaim(new Claim(CustomClaimTypes.IsEmployee, isEmployee));
它在上面一行给出了这个错误:
无法从 'bool?' 转换到“System.Security.Claims.ClaimsIdentity”
我发现的所有示例都是添加字符串。如何添加 bool、int 或其他类型?谢谢。
【问题讨论】: