?? login.aspx.vb
字號(hào):
Public Class WebForm4
Inherits System.Web.UI.Page
#Region " Web 窗體設(shè)計(jì)器生成的代碼 "
'該調(diào)用是 Web 窗體設(shè)計(jì)器所必需的。
<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 窗體設(shè)計(jì)器所必需的。
'不要?jiǎng)h除或移動(dòng)它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法調(diào)用是 Web 窗體設(shè)計(jì)器所必需的
'不要使用代碼編輯器修改它。
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
'用戶屬性設(shè)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'數(shù)據(jù)庫連接
Dim conn As New SqlClient.SqlConnection
'conn的連接字符串在下邊的case語句中進(jìn)行定義
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 '根據(jù)用戶身份登陸字符串
Dim strUserIdent As String '用戶身份標(biāo)識(shí)
Dim bool1 As Boolean = False '判斷是否通過驗(yàn)證
Dim strupdate As String '更新語句
Dim str_iflogin As String
'數(shù)據(jù)庫查詢語句---在此處添加語句--對(duì)用戶分類——設(shè)置用戶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 = "同學(xué)"
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
'驗(yàn)證用戶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 = "此賬戶已經(jīng)登錄在線!"
'End If
Else
Label4.Text = "密碼錯(cuò)誤!"
bool1 = False
End If
Else
Label4.Text = "用戶名輸入錯(cuò)誤!"
bool1 = False
End If
reader.Close()
Catch
Label4.Text = "數(shù)據(jù)庫操作失敗,可能是服務(wù)器出現(xiàn)錯(cuò)誤,請(qǐng)稍后再試!非常抱歉影響了您的工作!"
Finally
conn.Close()
strpassword = ""
strRealPw = ""
End Try
If bool1 Then '
'設(shè)置cookie參數(shù)
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") '創(chuàng)建新的cookie
cookie.values.add("userID", TextBox1.Text) '加入用戶的賬號(hào)
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) '進(jìn)入到主頁面
End If
End Sub
End Class
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -