2

我在 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

4

1 回答 1

0

谢谢大家。这似乎已经解决了这个问题。

EnableViewStateMAC="False"

于 2013-11-12T13:46:03.640 回答