Partial Class Index Inherits System.Web.UI.Page Dim username As String = "" Dim userpa


Partial Class Index
    Inherits System.Web.UI.Page

    Dim username As String = ""
    Dim userpass As String = ""

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Request.Cookies("username") IsNot Nothing And Request.Cookies("userpass") IsNot Nothing Then
            username = Server.HtmlEncode(Request.Cookies("username").Value)
            userpass = Server.HtmlEncode(Request.Cookies("userpass").Value)

            Dao.sds.SelectCommand = "select count(*) from t_user where username = @username and userpass = @userpass"
            Dao.sds.SelectParameters.Clear()
            Dao.sds.SelectParameters.Add("username", username)
            Dao.sds.SelectParameters.Add("userpass", userpass)

            Dim ie As IEnumerable = Dao.sds.Select(DataSourceSelectArguments.Empty)
            Dim dv As System.Data.DataView = ie
            Dim i As Integer = dv(0)(0)

            If i = 0 Then
                Response.Redirect("~/Default.aspx")
            End If
        Else
            Response.Redirect("~/Default.aspx")
        End If
    End Sub

    Protected Sub btn_exit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_exit.Click
        Response.Cookies("username").Expires = DateTime.Now.AddDays(-7) '设置cookie超时时间为7天
        Response.Cookies("userpass").Expires = DateTime.Now.AddDays(-7)
        Response.Redirect("~/Default.aspx")
    End Sub
End Class

发布了253 篇原创文章 · 获赞 25 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/eds124/article/details/87403391
今日推荐