Hom*_*mam 7 c# authentication asp.net-core asp.net-core-2.0
在 ASP.Net 核心 2.0 应用程序(带有 Angular 的 SPA)中,虽然 User.Identity.IsAuthenticated 返回 true,但 ClaimsPrincipal.Current 始终返回 false!
我需要在另一个项目中使用它而不是在控制器中使用它。我错过了什么?
dav*_*owl 10
ASP.NET Core没有设置ClaimsPrincipal.Current,如果需要的话可以在中间件中设置。
app.UseAuthentication();
...
app.Use(async (context, next) =>
{
Thread.CurrentPrincipal = context.User;
await next(context);
});
Run Code Online (Sandbox Code Playgroud)
默认声明主体选择器是基于的,Thread.CurrentPrincipal所以它应该可以工作。
| 归档时间: |
|
| 查看次数: |
4880 次 |
| 最近记录: |