By using this code, I get Claims so I can use it, but it warns me that it is empty
Warning have :
Claim? ClaimsIdentity.FindFirst(string type) (+ 1 overload)
Retrieves the first claim with the specified claim type.
Returns:
The first matching claim or null if no match is found.
Exceptions:
ArgumentNullException
CS8602: Dereference of a possibly null reference
if (HttpContext.User.Identity is ClaimsIdentity identity)
{
var IdUser = identity?.FindFirst(ClaimTypes.SerialNumber).Value;
}
>Solution :
FindFirst can return null, so you must also use the ? after it:
v = identity?.FindFirst(ClaimTypes.SerialNumber)?.Value;