Home > Blockchain >  Razor pages dereference of possible null reference on User.Identity.IsAuthenticated
Razor pages dereference of possible null reference on User.Identity.IsAuthenticated

Time:11-08

enter image description here

I have this if statement in the cshtml of a page. For some reason or another it keeps giving me that the User.Identity.IsAuthenticated is dereference of possible null reference and when the program starts it doesn't consider the statement.How can it be fixed?

this is after implementing your solution

Addition: the error occurs on post

CodePudding user response:

Use:

@if (User.Identity?.IsAuthenticated == true)
{
}

Check Nullable contexts and Null-conditional operators.

CodePudding user response:

I also get Dereference of possible null reference when using User.Identity.IsAuthenticated, but it's not ignored, it works, have you verified this page?

Other than that, maybe you can use Request.IsAuthenticated instead.

  • Related