登录页面中的代码需要其他页面上的代码才能读取会话
protected void btnLogin_Click(object sender, EventArgs e)
{
lblMessage.Text = loginService.userLogin(txtusername.Text, txtPassword.Text);
string user = txtusername.Text;
if (lblMessage.Text == "Logged In")
{
Response.Redirect("AMD.aspx?Name='"+user);
Session["user"] = txtusername.Text;
}
else
{
Response.Redirect("loginPage.aspx");
}
}
在第2页上调用会话的其他页面中的代码,以便我可以查看我的会话
ServiceReferenceUsers.ServicePubsClient serviceObj = new ServiceReferenceUsers.ServicePubsClient();
protected void Page_Load(object sender, EventArgs e)
{
lblMessage.Text = Request.QueryString["Name"].ToString();
Session["User"] = lblMessage.Text;
}
protected void btnLoad_Click(object sender, EventArgs e)
{
DataTable myData = new DataTable();
myData = serviceObj.viewUsers();
GridView1.DataSource = myData;
GridView1.DataBind();
}
答案 0 :(得分:0)
更改
Session["User"] = lblMessage.Text;
要
lblMessage.Text = Session["User"];
在你的第二页......飞行员错误? :)