Dim showmsg As New alertmessage
If TB1.Text <> "" And TB2.Text <> "" Then
m_con.ConnectionString = WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
If m_con.State = ConnectionState.Closed Then
m_con.Open()
End If
str = "select 密码,权限 from 用户信息表 where 用户名='" & TB1.Text & "'"
m_cmd.CommandText = str
m_cmd.Connection = m_con
m_ada.SelectCommand = m_cmd
m_ds.Clear()
m_ada.Fill(m_ds, "用户信息表")
If m_ds.Tables("用户信息表").Rows.Count <> 0 Then
Dim 数据密码 As String
Dim 权限 As String
数据密码 = m_ds.Tables("用户信息表").Rows(0).Item(0).ToString()
权限 = m_ds.Tables("用户信息表").Rows(0).Item(1).ToString() Dim md5 As New MD5
Dim 填写密码 As String = md5.MD5(TB2.Text, 32)
If 数据密码 = 填写密码 Then
'通过验证后将用户导向当初Request网页
FormsAuthentication.RedirectFromLoginPage(TB1.Text, True)
Else
showmsg.showMsg(Me.Page, "请输入正确的用户名和密码!") '账号验证不通过时所现实的信息
TB1.Focus()
TB1.Text = ""
TB2.Text = ""
End If
Else
showmsg.showMsg(Me.Page, "此用户名不存在!")
TB1.Focus()
TB1.Text = ""
TB2.Text = ""
End If
Else
If TB1.Text = "" Then
showmsg.showMsg(Me.Page, "请填写用户名信息!")
TB1.Focus()
Else
showmsg.showMsg(Me.Page, "请填写密码信息!")
TB2.Focus()
End If
End If
m_con.Close()
以上是我的LOGIN.ASPX页面用户登录时的代码。
我想询问各位大哥的是,如何在其它页面能够读取登录用户的用户权限,谢谢各位大哥了!
------解决方案--------------------------------------------------------
- C# code
//登录方法 public string[] UserLogin(string uname,string upwd) { try { SqlParameter[] parmer ={ SqlHelper.CreateCommandParameter("@uname",SqlDbType.VarChar,uname), SqlHelper.CreateCommandParameter("@upwd",SqlDbType.VarChar,upwd), }; string str = "Select * from users us,TradeUnion Tu where uname=@uname and upwd=@upwd and us.unitid=Tu.tid"; cmd = SqlHelper.CreateDbCommand(str, conn); cmd.Parameters.AddRange(parmer); string[] result = new string[3]; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { result[0] = dr["qx"].ToString();//权限 result[1] = dr["tname"].ToString();//登录名 result[2] = dr["unitid"].ToString();//真实姓名 dr.Close(); return result;//最后接收的时候也用string[]数据接收数据就ok了 } else { return null; } } catch (Exception e) { throw e; } finally { conn.Close(); } }//登录按钮 protected void IBok_Click(object sender, ImageClickEventArgs e) { Users u = new Users(); if (u.UserLogin(Tuser.Text.Trim(),Tpwd.Text.Trim())==null)//调用登录方法 { Response.Write("<script>alert('用户名或密码不正确!');</script>"); Tuser.Text = ""; Tpwd.Text = ""; } else { string[] result = new string[3]; result = u.UserLogin(Tuser.Text.Trim(), Tpwd.Text.Trim());//接收用户信息 Session["user"] = Tuser.Text; Session["qx"] = result[0].ToString(); Session["unit"] = result[1].ToString(); Session["unitid"] = result[2].ToString(); if (result[2].ToString() == "1") { Response.Redirect("MyDo.aspx"); } else { Response.Redirect("MyPinfo.aspx"); } Tuser.Text = ""; Tpwd.Text = ""; } }