我现在完成了登录代码编写,并已将登录信息记录到了session中。我前台代码应该怎样写,才能区分 用户登录前后的不同区域的不同内容显示有朋友能提供一段代码参考下,或者 帮忙讲解一下 具体的实现原理及步骤。 谢谢了

解决方案 »

  1.   

    用 session 做判断....
    不明加我qq  975292958
      

  2.   

    添加panel控件并将其设置为不可见,将登陆后才显示的部分添加到panel上,当登陆成功后显示该panel!
      

  3.   

      protected void Button1_Click(object sender, EventArgs e)
        {
            
                SqlConnection conn = new SqlConnection(SqlHelp.ConnectionString);
                SqlDataAdapter da = new SqlDataAdapter("select * from tbUsers where iUserName = '" + TextBox_iUserName.Text.Trim() + @"' and sPassword = '" + TextBox_sPassword.Text.Trim() + @"' ", conn);
                DataSet ds = new DataSet();
                try
                {
                    da.Fill(ds);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            Session["iUserName"] = ds.Tables[0].Rows[0]["iUserName"].ToString();
                            Session["sPassword"] = ds.Tables[0].Rows[0]["sPassword"].ToString();
                            Session["iUserID"] = ds.Tables[0].Rows[0]["iUserID"].ToString();
                            Session["iLevels"] = ds.Tables[0].Rows[0]["iLevels"].ToString();
                            Response.Redirect("main.aspx");
                        }
                        else
                        {
                            Response.Write("帐号或密码错误!");
                        }
                    }
                    else
                    {
                        Response.Write("帐号或密码错误!");
                    }
                }
                catch
                {            }
                finally
                {
                    conn.Close();
                    conn.Dispose();
                    conn = null;
                }
      

  4.   

    using(SqlConnection conn = new SqlConnection(""))
    {
                conn.Open(); 
                string sql = "select * from tb where name='" + name.Text + "'"; 
                SqlCommand command = new SqlCommand(sql, conn); 
                SqlDataReader reader = command.ExecuteReader(); 
                if (reader.Read()) 
                { 
                    if(dr["password"].ToString().Equals(txtpass.text.Trim()))
                    {
                    Session["name"] = name.Text; 
                    Response.Redirect("index.aspx"); }
                } 
                else 
                { 
                    Session["name"] = ""; 
                    Label1.Text = "登录失败,无此用户名或者密码不正确!"; 
                } 
    connc.Close();
    }
    或使用数据库操作类,查询数据或参数化
      

  5.   

    用户登录前后的不同区域的不同内容显示 
    什么意思不太懂判断session是否存在 写相关代码就可以了if(session["user"]==null)
    {
       Panel1.Visible = false;
    }
    else
    {
       Panel2.Visible = true;}