<%@ Page Language="VB" %>
<!DOCTYPE html>
<script runat="server">
Protected Sub Login1_Authenticate(sender As Object, e As AuthenticateEventArgs) Handles Login1.Authenticate
Dim username As String = Me.Login1.UserName.Trim().ToLower() '获取控件Login1的用户名
Dim userpass As String = Me.Login1.Password.Trim().ToLower() '获取控件Login1的密码
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 = @userpass") '新建一个数据源控件
sds.SelectParameters.Add("username", username) '预处理
sds.SelectParameters.Add("userpass", userpass) '预处理
Dim dv As System.Data.DataView = sds.Select(DataSourceSelectArguments.Empty) '定义一个数据视图接收数据源的查询方法
Dim b As Boolean = dv(0)(0) '取出数据视图的第一行第一列
If b Then '判断第一行第一列不为0就是真
Response.Cookies("username").Value = username '设置会话用户名
Response.Cookies("userpass").Value = userpass '设置会话密码
Response.Redirect("~/default.aspx") '跳转到默认页面
Return
End If
End Sub
Protected Sub Page_Load(sender As Object, e As EventArgs)
Response.Cookies.Clear()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server">
</asp:Login>
</div>
</form>
</body>
</html>
cookie版本的http://localhost:49648/login.aspx
最新推荐文章于 2022-10-25 15:49:27 发布