问题
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;
}
回答1:
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.
来源:https://stackoverflow.com/questions/4519034/page-user-identity-isauthenticated-returns-object-reference-not-set-to-instance