Pou*_*sen 9 claims-based-identity
我有以下方法:
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (Composite.C1Console.Security.UserValidationFacade.IsLoggedIn())
SetPrincipal(request, new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Role, "Administrator") },)));
var test = request.GetClaimsPrincipal();
return base.SendAsync(request, cancellationToken);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我检查test.Identity.IsAuthenticated是没有设置为真.这只是一些测试代码来弄清楚如何.我错过了什么
您需要为构造函数指定一个ClaimsIdentity实例,该实例ClaimsPrincipal指定一个authenticationType诸如“ Basic” 的实例。索赔可以null。
var principal = new ClaimsPrincipal(new ClaimsIdentity(null, "Basic"));
var isAuthenticated = principal.Identity.IsAuthenticated; // true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8569 次 |
| 最近记录: |