Page.User.Identity.IsAuthenticated returns object reference not set to instance of object

元气小坏坏 提交于 2019-12-08 01:46:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!