Partial Class _Default
Inherits System.Web.UI.Page
Private Shared conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(Dao.ConnectionString)
Private Shared comm As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("select count(*) from t_user where username = @username and userpass = @userpass", conn)
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Try
Dim username As String = Request.Cookies("username").Value
Dim userpass As String = Request.Cookies("userpass").Value
comm.Parameters.Clear() '删除原有参数
comm.Parameters.AddWithValue("username", username) '预处理
comm.Parameters.AddWithValue("userpass", userpass)
If conn.State = Data.ConnectionState.Closed Then '页面型单例模式保证一个conn链接
conn.Open()
End If
Dim o As Object = comm.ExecuteScalar() '查询第一行第一列
If o < 1 Then
Response.Redirect("~/Login.aspx")
End If
Catch ex As Exception
Response.Redirect("~/Login.aspx")
End Try
End Sub
End Class
file:///E:\WebSite\Default.aspx.vb
最新推荐文章于 2023-07-02 15:49:42 发布