Check if user is logged in with Token Based Authentication in ASP.NET Core

后端 未结 2 956
小鲜肉
小鲜肉 2021-01-03 22:04

I managed to implement this token based authentication system in my application, but I have a little question. How can I check if a user is signed it (eg if the there is a v

2条回答
  •  情话喂你
    2021-01-03 22:11

    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;
    

提交回复
热议问题