Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net select case语句引发NullReferenceException。你知道为什么吗?_.net_Asp.net_Vb.net - Fatal编程技术网

.net select case语句引发NullReferenceException。你知道为什么吗?

.net select case语句引发NullReferenceException。你知道为什么吗?,.net,asp.net,vb.net,.net,Asp.net,Vb.net,这个错误在生产中偶尔出现,但我无法在DEV中重现 System.NullReferenceException: Object reference not set to an instance of an object. at CommandCenterHeader.ascx.vb:line 23 at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Web.UI.Control.OnL

这个错误在生产中偶尔出现,但我无法在DEV中重现

System.NullReferenceException: Object reference not set to an instance of an object.     
at CommandCenterHeader.ascx.vb:line 23     
at System.EventHandler.Invoke(Object sender, EventArgs e)     
at System.Web.UI.Control.OnLoad(EventArgs e)     
at System.Web.UI.Control.LoadRecursive()     
at System.Web.UI.Control.LoadRecursive()     
at System.Web.UI.Control.LoadRecursive()     
at System.Web.UI.Control.LoadRecursive()     
at System.Web.UI.Control.LoadRecursive()     
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
CommandCenterHeader.ascx.vb:第23行是“选择Case Me.CurrentUser.UserType.ToLower”

Protected Sub Page_Load(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Load
如果不是的话,我会回来的
选择Case Me.CurrentUser.UserType.ToLower
案例“e”、“f”
lbtnccadmin.Visible=True
lbtnccadmin.NavigateUrl=“/commandcenter/cc_admin.aspx”
其他情况
lbtnccadmin.Visible=False
结束选择
如果结束
端接头
_
受保护的只读属性CurrentUser()为CypStdLib.FL.QuotesDB.tblUserInfo
得到
如果(notisnothing(Request.Cookies(cookieKey)))和(notisnothing(Request.Cookies(cookieKey)(“userid”)),那么
Dim uid As String=Request.Cookies(cookieKey)(“用户ID”)&“
如果uid“”和也为数字(uid),则
Dim curruser作为新的CypStdLib.FL.QuotesDB.tblUserInfo
如果curruser.LoadByPrimaryKey(CLng(uid))则
会话(“当前用户”)=当前用户
返回用户
如果结束
如果结束
如果结束
一无所获
结束
'设置(ByVal值为CypStdLib.FL.QuotesDB.tblUserInfo)
'Current.Session(“CurrentUser”)=值
'端集
端属性

那么,
当前用户是否为空?如果不是,则
CurrentUser.UserType
null

另外,
ToLower
需要作为方法调用
ToLower()

清楚 层次结构中的对象
Me.CurrentUser.UserType.ToLower
是空的。
Me
Me.CurrentUser
Me.CurrentUser.UserType

如果你想不出为什么它可能是空的,或者什么可能是空的..你可以在开关盒之前添加一个log msg,并将其存储在文件或数据库中,然后将用于测试的代码发送到生产中(一段时间,直到你找出错误为止)。
这将使您了解什么是错误的

当web应用程序中的用户会话超时时,是否会发生这种情况?

然后是
CurrentUser
CurrentUser.UserType
nothing,它们是什么以及在哪里初始化它们?Eiter
Me.CurrentUser
为null或
Me.CurrentUser.UserType
null
;如果您无法在生产环境中进行调试,只需添加日志记录即可。我认为括号对于无参数方法是可选的。VB.NET不是C#,您可以调用不带参数的方法(带括号或不带括号)。实际上,
Me
永远不能是
Nothing
。因此它必须是
CurrentUser
UserType
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Select Case Me.CurrentUser.UserType.ToLower
            Case "e", "f"
                lbtnccadmin.Visible = True
                lbtnccadmin.NavigateUrl = "/commandcenter/cc_admin.aspx"
            Case Else
                lbtnccadmin.Visible = False
        End Select
    End If
End Sub

<ComponentModel.Browsable(False)> _
    Protected ReadOnly Property CurrentUser() As CypStdLib.FL.QuotesDB.tblUserInfo
        Get
            If (Not IsNothing(Request.Cookies(cookieKey))) AndAlso (Not IsNothing(Request.Cookies(cookieKey)("userid"))) Then
                Dim uid As String = Request.Cookies(cookieKey)("userid") & ""
                If uid <> "" AndAlso IsNumeric(uid) Then
                    Dim curruser As New CypStdLib.FL.QuotesDB.tblUserInfo
                    If curruser.LoadByPrimaryKey(CLng(uid)) Then

                        Session("CurrentUser") = curruser
                        Return curruser
                    End If
                End If
            End If

            Return Nothing
        End Get
        'Set(ByVal value As CypStdLib.FL.QuotesDB.tblUserInfo)
        '    Current.Session("CurrentUser") = value
        'End Set
    End Property