版权声明: https://blog.csdn.net/eds124/article/details/86071748
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Login1_Authenticate(sender As Object, e As AuthenticateEventArgs) Handles Login1.Authenticate
Dim username As String = Me.Login1.UserName.Trim().ToLower()
Dim password As String = Me.Login1.Password.Trim().ToLower()
Dim b As Boolean = Me.Login1.RememberMeSet
Dim sds As SqlDataSource = New SqlDataSource("Data Source=.;Initial Catalog=mydata;User ID=sa;Password=Abcdefg1", "select count(*) from t_user where username = @username and userpass = @password")
If b Then
sds.SelectCommand = "select count(*) from t_root where rootname = @username and rootpass = @password"
End If
sds.SelectParameters.Add("username", username)
sds.SelectParameters.Add("password", password)
Dim ie As IEnumerable = sds.Select(DataSourceSelectArguments.Empty)
Dim dv As System.Data.DataView = CType(ie, System.Data.DataView)
Dim o As Object = dv(0)(0)
Dim s As String = o.ToString()
If s.Equals("0") Then
Response.Write("登录失败")
Return
End If
If b Then
Session("rootname") = username
Session("rootpass") = password
Response.Redirect("~/Root/Default.aspx")
Return
End If
Session("username") = username
Session("userpass") = password
Response.Redirect("~/Default.aspx")
End Sub
Protected Sub Login1_Init(sender As Object, e As EventArgs) Handles Login1.Init
Me.Login1.RememberMeText = "管理员登录"
End Sub
End Class