怎样用ASP.NET做登陆系统
发布网友
发布时间:2022-04-30 01:33
我来回答
共1个回答
热心网友
时间:2022-06-28 03:25
做登入就要用到数据库,先和数据库建立连接,然后检索数据库的的字段,如果"用户名"和"密码"都相同的情况下,就能登入,否则就跳转到登入页面.做登入的思想一般都这样.下面是我以前做过的,数据库用的是ACCESS的,希望对你有帮助,界面是:两个文本框两个按钮.
Dim conn As New Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=D:\asp.net44\fww.mdb;")
Dim comm As New Data.OleDb.OleDbCommand()
conn.Open()
Try
Dim un As String
Dim pwd As String
comm.Connection = conn
comm.CommandText = "select * from admin "
Dim dr As Data.OleDb.OleDbDataReader = comm.ExecuteReader
If dr.Read Then
un = Trim(dr("user"))
pwd = Trim(dr("password"))
If un = TextBox1.Text And pwd = TextBox2.Text Then
Session("xingming") = TextBox1.Text
Session("mima") = TextBox2.Text
TextBox1.Text = ""
TextBox2.Text = ""
Response.Redirect("index.aspx")
End If
If TextBox1.Text = "" Then
MsgBox("用户名不能为空!")
TextBox1.Text = ""
End If
If TextBox2.Text = "" Then
MsgBox("密码不能为空!")
TextBox1.Text = ""
End If
If un <> TextBox1.Text Or pwd <> TextBox2.Text Then
MsgBox("用户名或密码错误!")
TextBox1.Text = ""
End If
End If
Catch ex As Exception
Response.Write(ex.Message)
Finally
If Nothing Then comm.Cancel()
If Nothing Then conn.Close()
End Try
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class