Page.User.Identity.IsAuthenticated returns object reference not set to instance of object
this works fine on my local site but as soon as i upload the site to my live server i get stem.开发者_开发问答NullReferenceException: Object reference not set to an instance of an object
on the first line of this:
if (!Page.User.Identity.IsAuthenticated)
{
pnlSignIn.Visible = true;
pnlSignOut.Visible = false;
}
You should use Request.IsAuthenticated
instead of Page.User.Identity.IsAuthenticated
.
Internally Request.IsAuthenticated
will verify that the User and it's Identity are set (not null). You could do the same in your code, but why bother.
精彩评论