<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim sds As SqlDataSource = New SqlDataSource(Dao.ConnectionString, "select a from t_user where username = @username and userpass = @userpass")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Cookies("username").Value = "" '清除登陆
Response.Cookies("userpass").Value = ""
End Sub
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
sds.SelectParameters.Add("username", Me.Login1.UserName.Trim().ToLower()) '预处理
sds.SelectParameters.Add("userpass", Me.Login1.Password.Trim().ToLower()) '预处理
If CType(sds.Select(DataSourceSelectArguments.Empty), System.Data.DataView)(0)(0) Then '判断第一行第一列不为0就是真
Response.Cookies("username").Value = Me.Login1.UserName.Trim().ToLower() '设置会话用户名
Response.Cookies("userpass").Value = Me.Login1.Password.Trim().ToLower() '设置会话密码
Response.Redirect("~/Index.aspx") '跳转到默认页面
Return
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server">
</asp:Login>
</div>
</form>
</body>
</html>
file:///C:\Users\j\Desktop\WebSite\Default.aspx未经过后台数据库验证,但应该是对的
最新推荐文章于 2024-08-12 23:02:50 发布