Page.User.Identity.IsAuthenticated返回对象引用不设置到对象实例 [英] Page.User.Identity.IsAuthenticated returns object reference not set to instance of object

查看:208
本文介绍了Page.User.Identity.IsAuthenticated返回对象引用不设置到对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上传到我的实时服务器能正常工作在我的本地网站,但一旦我得到stem.NullReferenceException:对象引用不设置到对象的实例

在这第一行:

 如果(!Page.User.Identity.IsAuthenticated)
{
    pnlSignIn.Visible =真;
    pnlSignOut.Visible = FALSE;
}


解决方案

您应该使用 Request.IsAuthenticated 而不是 Page.User.Identity。 IsAuthenticated

在内部 Request.IsAuthenticated 将验证用户,它的身份设置(NOT NULL)。你可以做同样的在你的code,但何必呢。

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.

这篇关于Page.User.Identity.IsAuthenticated返回对象引用不设置到对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆