本文介绍了如何检查用户是否是超级用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表,其中我有四列id,用户名,密码和SuperUser。当我登录时,我想向普通用户和整个页面显示特定页面给超级用户。我尝试的是:



 protected void LoginButton_Click(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(@数据源= ashish-pc \;初始目录= HMS;集成安全性=真);
con.Open();
SqlCommand cmd = new SqlCommand(select * from Login where UserName = @ UserName and Password = @ Password,con);
cmd.Parameters.AddWithValue(@ UserName,UserName.Text.Trim());
cmd.Parameters.AddWithValue(@ Password,Password.Text.Trim());
cmd.Parameters.Add(IsSuperUser);


SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet dt = new DataSet();

da.Fill(dt);
if(dt.Tables [0] .Rows.Count> 0)
{



Session [UserName] = UserName.Text ;
Session.Timeout = 1;

//会话[登录] =
Response.Redirect(/ Home.aspx);

}
else
{
Response.Write(用户名和密码无效);
}
con.Close();
}





请帮助

解决方案

I have a login table in which i have four columns id, username, password and SuperUser. when i login i want to show specific pages to normal user and whole pages to superuser. what i tried is:

protected void LoginButton_Click(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Login where UserName=@UserName and Password=@Password", con);
            cmd.Parameters.AddWithValue("@UserName", UserName.Text.Trim() );
            cmd.Parameters.AddWithValue("@Password", Password.Text.Trim());
            cmd.Parameters.Add("IsSuperUser");


            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet dt = new DataSet();

            da.Fill(dt);
            if (dt.Tables[0].Rows.Count>0)
            {



                Session["UserName"] = UserName.Text;
                Session.Timeout = 1;

                //Session["Login"] =
                Response.Redirect("/Home.aspx");

            }
            else
            {
                 Response.Write("Invalid username and password");
            }
            con.Close();
        }



please help

解决方案


这篇关于如何检查用户是否是超级用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 08:53