0
try
{
    string signedInUserID = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
    //do some stuff if the user is singed in
}
Catch
{
    //do some stuff if the user is singed in
}

Is there a better way to check if the user is signed in?

StuartLC
  • 104,537
  • 17
  • 209
  • 285
Stefan
  • 555
  • 5
  • 18

1 Answers1

1

You can always check using User.Identity.IsAuthenticated like following.

    if(User.Identity.IsAuthenticated)
    {
        //Authenticated 
    }
    else
    {
        //Not Authenticated
    }

Note: Claims are mainly used to store additional data and more for Authorization purpose.

PSK
  • 17,547
  • 5
  • 32
  • 43