且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查用户是否在ASP.NET Core中使用基于令牌的身份验证登录

更新时间:2023-11-30 17:54:16

您不需要使用SigninManager或类似的东西。将用户注入到管道中(在基本控制器的User属性上),身份验证中间件(cookie或令牌)会自动填充其信息。因此,在您的控制器上:

You don't need to use the SigninManager or something similar. The user is injected on the pipeline (on the User property of the base controller) and it's info is filled automatically by the authentication middleware (cookie or token). So, on your controller:

bool isAuthenticated = User.Identity.IsAuthenticated;