登录页面空闲时出现未处理的异常错误

时间:2013-11-06 15:25:33

标签: asp.net vb.net

我已经在vb.net开发了一个网站(在我的兄弟的帮助下),它几乎准备推出,除了我在登录时遇到未处理的异常错误 当页面闲置几分钟时屏幕。我是vb.net的新手,而不是程序员:(任何帮助都会非常感激。抱歉,如果我的帖子中的任何内容都不符合网站标准,因为这是我的第一篇帖子。)

我不确定为什么会这样。在login_buttonClick上执行的代码是:

Protected Sub LoginWizard_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles LoginWizard.FinishButtonClick

    Dim oUsername As String = txtUsername.Text
    Dim oPassword As String = txtPassword.Text

    Dim oPath As String = Server.MapPath("App_Data/IOFR.mdb")
    Dim oValid As Boolean = False

    Dim oReader As System.Data.OleDb.OleDbDataReader = Nothing
    Dim oConnection As System.Data.OleDb.OleDbConnection = Nothing

    Dim oName As String = ""
    Dim oOrg As String = ""
    Dim oUserId As Integer = 0
    Dim oActiveAcc As String = ""
    Dim oSessionExpire As Integer = 0

    Try
        oConnection = New System.Data.OleDb.OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Jet OLEDB:Database Password=EdmundColin13", oPath))
        oConnection.Open()

        Dim ipAddress As String = Request.ServerVariables("REMOTE_ADDR")
        Dim cmd As New SqlCommand

        Dim oParams As New List(Of System.Data.OleDb.OleDbParameter)
        oParams.Add(New System.Data.OleDb.OleDbParameter("@pmUsername", oUsername))
        oParams.Add(New System.Data.OleDb.OleDbParameter("@pmPassowrd", oPassword))

        Dim oCommand As New System.Data.OleDb.OleDbCommand("SELECT ID, [Name], Organisation, ActiveAccount, [Password] FROM Users WHERE [Username] = @pmUsername AND [Password] = @pmPassword", oConnection)
        oCommand.Parameters.AddRange(oParams.ToArray)
        oReader = oCommand.ExecuteReader()

        If oReader.Read() Then
            oValid = True
            oName = oReader.GetString(oReader.GetOrdinal("Name"))
            oActiveAcc = oReader.GetString(oReader.GetOrdinal("ActiveAccount"))
            oOrg = oReader.GetString(oReader.GetOrdinal("Organisation"))
            oPassword = oReader.GetString(oReader.GetOrdinal("Password"))
            oUserId = oReader.GetInt32(oReader.GetOrdinal("ID"))
            oSessionExpire = oReader.GetInt32(oReader.GetOrdinal("SessionExpire"))
        End If
    Catch ex As Exception
    Finally
        If Not oReader Is Nothing Then
            If Not oReader.IsClosed Then
                oReader.Close()
            End If
            oReader = Nothing
        End If

    End Try
    If oValid And Not String.Equals(txtPassword.Text, oPassword) Then
        oValid = False
    End If

    If oValid Then

        If oActiveAcc = "No" Then
            Response.Redirect("~/DisabledAccount.aspx")
            Return
        End If

        Session("username") = txtUsername.Text
        Session("name") = oName
        Session("org") = oOrg

        'Generate session id and store it in session
        Dim uniquesessionid As String = Guid.NewGuid().ToString()
        Session("uid") = uniquesessionid

        Dim oCommandSession As New System.Data.OleDb.OleDbCommand("UPDATE Users SET SessionId = @pmid, SessionExpire = '" & DateTime.Now.AddHours(2).ToString() & "' WHERE [ID] = @pmUserid", oConnection)
        oCommandSession.Parameters.Add(New System.Data.OleDb.OleDbParameter("@pmid", uniquesessionid))
        oCommandSession.Parameters.Add(New System.Data.OleDb.OleDbParameter("@pmUserid", oUserId))
        oCommandSession.ExecuteNonQuery()
        Response.Redirect("~/Home.aspx?login=true")
    Else
        txtUsername.BorderColor = Drawing.Color.Red
        txtUsername.BackColor = Drawing.Color.Red
        txtPassword.BorderColor = Drawing.Color.Red
        FailedLogin.Visible = True
    End If

    If Not oConnection Is Nothing Then
        If oConnection.State = Data.ConnectionState.Open Then
            oConnection.Close()
        End If
    End If
End Sub

Dim oUsername As String = txtUsername.Text Dim oPassword As String = txtPassword.Text Dim oPath As String = Server.MapPath("App_Data/IOFR.mdb") Dim oValid As Boolean = False Dim oReader As System.Data.OleDb.OleDbDataReader = Nothing Dim oConnection As System.Data.OleDb.OleDbConnection = Nothing Dim oName As String = "" Dim oOrg As String = "" Dim oUserId As Integer = 0 Dim oActiveAcc As String = "" Dim oSessionExpire As Integer = 0 Try oConnection = New System.Data.OleDb.OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Jet OLEDB:Database Password=EdmundColin13", oPath)) oConnection.Open() Dim ipAddress As String = Request.ServerVariables("REMOTE_ADDR") Dim cmd As New SqlCommand Dim oParams As New List(Of System.Data.OleDb.OleDbParameter) oParams.Add(New System.Data.OleDb.OleDbParameter("@pmUsername", oUsername)) oParams.Add(New System.Data.OleDb.OleDbParameter("@pmPassowrd", oPassword)) Dim oCommand As New System.Data.OleDb.OleDbCommand("SELECT ID, [Name], Organisation, ActiveAccount, [Password] FROM Users WHERE [Username] = @pmUsername AND [Password] = @pmPassword", oConnection) oCommand.Parameters.AddRange(oParams.ToArray) oReader = oCommand.ExecuteReader() If oReader.Read() Then oValid = True oName = oReader.GetString(oReader.GetOrdinal("Name")) oActiveAcc = oReader.GetString(oReader.GetOrdinal("ActiveAccount")) oOrg = oReader.GetString(oReader.GetOrdinal("Organisation")) oPassword = oReader.GetString(oReader.GetOrdinal("Password")) oUserId = oReader.GetInt32(oReader.GetOrdinal("ID")) oSessionExpire = oReader.GetInt32(oReader.GetOrdinal("SessionExpire")) End If Catch ex As Exception Finally If Not oReader Is Nothing Then If Not oReader.IsClosed Then oReader.Close() End If oReader = Nothing End If End Try If oValid And Not String.Equals(txtPassword.Text, oPassword) Then oValid = False End If If oValid Then If oActiveAcc = "No" Then Response.Redirect("~/DisabledAccount.aspx") Return End If Session("username") = txtUsername.Text Session("name") = oName Session("org") = oOrg 'Generate session id and store it in session Dim uniquesessionid As String = Guid.NewGuid().ToString() Session("uid") = uniquesessionid Dim oCommandSession As New System.Data.OleDb.OleDbCommand("UPDATE Users SET SessionId = @pmid, SessionExpire = '" & DateTime.Now.AddHours(2).ToString() & "' WHERE [ID] = @pmUserid", oConnection) oCommandSession.Parameters.Add(New System.Data.OleDb.OleDbParameter("@pmid", uniquesessionid)) oCommandSession.Parameters.Add(New System.Data.OleDb.OleDbParameter("@pmUserid", oUserId)) oCommandSession.ExecuteNonQuery() Response.Redirect("~/Home.aspx?login=true") Else txtUsername.BorderColor = Drawing.Color.Red txtUsername.BackColor = Drawing.Color.Red txtPassword.BorderColor = Drawing.Color.Red FailedLogin.Visible = True End If If Not oConnection Is Nothing Then If oConnection.State = Data.ConnectionState.Open Then oConnection.Close() End If End If End Sub

1 个答案:

答案 0 :(得分:0)

全部谢谢。这种接缝解决了这个问题。      

      EnableViewStateMAC="False"