用C#/.net编写用户登录代码问题..

来源:百度知道 编辑:UC知道 时间:2024/06/07 14:31:49
如何用C#/.net编写用户登录成功后显示用户信息?

比如 像discuz论坛的登录步骤:
1.在首页输入用户名和密码;
2.登录成功后,有一个页面为跳转信息;
3.跳转完毕,首页显示用户的账号(或昵称),首页又添加了 用户的控制面板等信息.

这样的代码如何编写?

登陆页面:
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "server=localhost;database=word;uid=sa;pwd=622577";
SqlConnection conn = new SqlConnection(sql);
conn.Open();
string dl = "select * from userinfo where username='" + textbox1.Text + "'and password='" + textbox2.Text + "'";
SqlCommand comm = new SqlCommand(dl,conn);
comm.ExecuteNonQuery();

int look = Convert.ToInt32(comm.ExecuteScalar());
if (look == 0)
{
Response.Redirect("default.aspx?username="+Textbox1.text);
}
else
{
response.write("<script>alert(\"该用户已存在\")</script>")
}
conn.Close();
}

然后跳转的那个页面也就是default.aspx里在page_load事件里写: string a = Request.QueryStr