我的登录页面有问题. [英] i have a problem in my log in page.

查看:78
本文介绍了我的登录页面有问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的登录页面有问题.

这是我的代码.

hello guys, i have a problem in my log in page.

this is my code.

Imports System
Imports System.Collections.Generic
'Imports System.Ling
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label1.Text = ""
        'SqlDataSource1.ConnectionString = "Data Source=ML0002298641\SQLEXPRESS;Initial Catalog=dbFluor;Integrated Security=True"

        If Not Me.IsPostBack Then
            ViewState("LoginErrors") = 0
        End If
    End Sub

    'Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As AuthenticateEventArgs)
    '    If YourValidationFunction(Login1.UserName, Login1.Password) Then
    ' e.Authenticated = true;
    '        Login1.Visible = False
    '        Label1.Text = "Successfully Logged In"
    '    Else
    '        e.Authenticated = False
    '    End If
    'End Sub

    Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As EventArgs)
        If ViewState("LoginErrors") Is Nothing Then
            ViewState("LoginErrors") = 0
        End If
        Dim ErrorCount As Integer = CInt(ViewState("LoginErrors")) + 1
        ViewState("LoginErrors") = ErrorCount
        If (ErrorCount > 3) AndAlso (Login1.PasswordRecoveryUrl <> String.Empty) Then
            Response.Redirect(Login1.PasswordRecoveryUrl)
        End If
    End Sub

    Private Function YourValidationFunction(ByVal UserName As String, ByVal Password As String) As Boolean
        Dim boolReturnValue As Boolean = False
        Dim strConnection As String = "Data Source=10.16.67.73;Initial Catalog=TestSQL;Integrated Security=True" '"server=.;Database=Database;uid=sa;pwd=wintellect;"
        'Dim strConnection As String = "Server=.\SQLExpress;DataBase=TestSQL;Integrated Security=SSPI"
        Dim sqlConnection As New SqlConnection(strConnection)
        'Dim SQLQuery As String = "SELECT LogName, LogPass FROM tblLog"
        Dim SQLQuery As String = "SELECT     LogMe.*, User_ID AS Expr1, Name AS Expr2, Cost_Center AS Expr3, Role_ID AS Expr4, Password AS Expr5 LogName = '" & Login1.UserName & "' AND LogPass = '" & Login1.Password & "' "

        Dim command As New SqlCommand(SQLQuery, sqlConnection)
        Dim Dr As SqlDataReader

        sqlConnection.Open()

        Dr = command.ExecuteReader()

        While Dr.Read()

            If (UserName = Dr("LogName").ToString()) And (Password = Dr("LogPass").ToString()) Then
                boolReturnValue = True
            End If

            Dr.Close()
            Return boolReturnValue
        End While
        Return boolReturnValue
    End Function


    Protected Sub Login1_Authenticate1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        If YourValidationFunction(Login1.UserName, Login1.Password) Then
            ' e.Authenticated = true;
            Login1.Visible = False
            Label1.Text = "Successfully Logged In"

        Else
            e.Authenticated = False
        End If
    End Sub
End Class



我在这方面遇到了问题.



and i have getting a problem in this line.

Dr = command.ExecuteReader()

       While Dr.Read()

           If (UserName = Dr("LogName").ToString()) And (Password = Dr("LogPass").ToString()) Then
               boolReturnValue = True
           End If

           Dr.Close()
           Return boolReturnValue
       End While



我希望你能帮助我.
谢谢



i hope you can help me.
thank you

推荐答案

尝试这个

try this

If (UserName == Dr("LogName").ToString()) And (Password == Dr("LogPass").ToString()) Then


尝试将Dr.Close()置于while循环之外
try Putting Dr.Close() outsite the while loop


这篇关于我的登录页面有问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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