ASP.NET Core › Authentication
What is the difference between IAuthenticationService's SignInAsync/SignOutAsync methods and simply checking if a user 'is authenticated'?
IntermediateAnswer
SignInAsync/SignOutAsync are imperative actions that actually establish or clear an authenticated session (writing/clearing a cookie, or in the case of custom schemes, whatever persistence mechanism the scheme uses) -- distinct from HttpContext.User.Identity.IsAuthenticated, which is merely a read-only check of the current request's already-established identity state, not an action that changes anything.
// Action: actually establishes a new authenticated session
await HttpContext.SignInAsync(scheme, principal);
// Query: just reads the CURRENT request's already-established state
bool isLoggedIn = HttpContext.User.Identity?.IsAuthenticated ?? false;Real-world example A login action handler calls SignInAsync once after validating credentials to establish the session, while every other part of the application simply reads User.Identity.IsAuthenticated to check the already-established state without triggering any new sign-in action.