⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.aspx.vb

📁 该源代码包括了asp.net的整个实现过程
💻 VB
字号:
Public Class WebForm4
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label
    Protected WithEvents Image1 As System.Web.UI.WebControls.Image

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Not IsPostBack Then
            '用户属性设
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '数据库连接
        Dim conn As New SqlClient.SqlConnection
        'conn的连接字符串在下边的case语句中进行定义
        Dim cmd As New SqlClient.SqlCommand
        cmd.Connection = conn
        '定义变量
        Dim strpassword As String
        Dim strRealPw As String
        Dim strTableName As String = DropDownList1.SelectedItem.Value      '用户登陆表名
        Dim strID As String                       '用户ID字符串
        Dim str_PW As String                       '用户密码字符串
        Dim strPath As String              '根据用户身份登陆字符串
        Dim strUserIdent As String         '用户身份标识
        Dim bool1 As Boolean = False                   '判断是否通过验证	
        Dim strupdate As String         '更新语句	
        Dim str_iflogin As String


        '数据库查询语句---在此处添加语句--对用户分类——设置用户ID字符串
        Dim flag As Boolean = True

        Select Case strTableName
            Case "student_login"
                conn.ConnectionString = ConfigurationSettings.AppSettings("DSN_student")
                strID = "S_ID"
                str_PW = "SL_pwd"
                'str_iflogin = "sl_if"
                strPath = "../network_course/student/index.aspx"
                strUserIdent = "同学"
            Case "teacher_login"
                conn.ConnectionString = ConfigurationSettings.AppSettings("DSN_teacher")
                strID = "T_ID"
                str_PW = "TL_pwd"
                'str_iflogin = "tl_if"
                strPath = "../network_course/teacher/index.aspx"
                strUserIdent = "老师"
        End Select

        '验证用户ID和密码
        cmd.CommandText = "select * from " + strTableName + " where " + strID + "='" & TextBox1.Text & "'" '查询语句
        Try
            conn.Open()
            Dim reader As IDataReader
            reader = cmd.ExecuteReader()
            strpassword = TextBox2.Text
            If reader.Read Then
                strRealPw = reader.Item(str_PW)

                If Trim(strpassword) = Trim(strRealPw) Then    '比较密码和输入
                    'If reader.Item(str_iflogin) = 0 Then
                    bool1 = True
                    'Else
                    '    Label4.Text = "此账户已经登录在线!"
                    'End If
                Else
                    Label4.Text = "密码错误!"
                    bool1 = False
                End If
            Else
                Label4.Text = "用户名输入错误!"
                bool1 = False
            End If
            reader.Close()
        Catch
            Label4.Text = "数据库操作失败,可能是服务器出现错误,请稍后再试!非常抱歉影响了您的工作!"
        Finally
            conn.Close()
            strpassword = ""
            strRealPw = ""
        End Try

        If bool1 Then '
            '设置cookie参数
            Dim userName As String
            Dim userIdentity As String
            Dim userRealName As String

            If (Request.Cookies("userInf")) Is Nothing Then
                Dim cookie As HttpCookie = New HttpCookie("userInf")        '创建新的cookie
                cookie.values.add("userID", TextBox1.Text)                   '加入用户的账号
                cookie.values.add("userIdent", strUserIdent)
                Response.AppendCookie(cookie)
            Else
                Dim cookie As HttpCookie = New HttpCookie("userInf")
                cookie.values("userID") = TextBox1.Text
                cookie.values("userIdent") = strUserIdent
                Response.AppendCookie(cookie)
            End If

            Response.Redirect(strPath)     '进入到主页面

        End If
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -