日期:2014-05-20  浏览次数:20390 次

登录后主页显示的用户名如何转换?
登录页面的代码: protected void Button1_Click(object sender, EventArgs e)
  {
  string text = this.TextBox3.Text.ToString();//获得用户输入的验证码
  string chkcode = Request.Cookies["validateCookie"].Values["ChkCode"].ToString();//获得系统生成的验证码
  string conn = "Data Source=172.18.1.12,1533;Persist Security Info=True;Password=adminbbxsqlweb;User ID=sa;Initial Catalog=IV_ScmDB";
  SqlConnection cn = new SqlConnection(conn);
  cn.Open();
  SqlCommand cmd = new SqlCommand("select * from Web_User where UserID='" + this.TextBox1.Text.Trim() + "' and Password='" + this.TextBox2.Text.Trim() + "' ", cn);
  if (cmd.ExecuteReader().Read())
  {
  this.Session["Username"] = this.TextBox1.Text.Trim();
  FormsAuthentication.SetAuthCookie(this.TextBox1.Text, false);
  if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(chkcode))
  {
  if (!chkcode.Equals(chkcode.ToUpper()))//如果系统生成的不为大写则转换成大写形式
  chkcode.ToUpper();
  if (text.ToUpper().Trim().Equals(chkcode.Trim())) //将输入的验证码转换成大写并与系统生成的比较
  base.Response.Redirect("Home.aspx");
   
  // this.Label1.Text = "验证正确!";
  else
  {
  this.Label1.Text = "验证错误!";
  }
  }
  else if (string.IsNullOrEmpty(text))
  {
  this.Label1.Text = "请输入验证码!";
  }
  }
  else
  {
  //base.Response.Write("<script>alert('用户名或密码错误!')</script>");
  this.Label1.Text = "用户名或密码错误!";
  }
  cn.Close();
  }

主页显示登录用户的代码:
 protected void Page_Load(object sender, EventArgs e)
  {
  Label1.Text = Session["Username"].ToString();
  }
到这里有个问题:主页上显示的比如是:admin(用户表的userid字段) 如何显示成 系统管理员呢(用户表username字段)?
求高手指点

------解决方案--------------------
...登陆的时候保存一整个user实体对象 然后登录名那取user.username从session中取