http://localhost:50280/WebSite2019-1-7/Login.aspx.vb 一个login控件解决管理员和普通用户登录问题


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) '转换成DataView
        Dim o As Object = dv(0)(0) '取出第一行第一列
        Dim s As String = o.ToString() '转成字符串
        If s.Equals("0") Then '0代表没有
            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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值