如何在C#中查看会话

时间:2015-03-25 17:21:18

标签: asp.net session

登录页面中的代码需要其他页面上的代码才能读取会话

 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();
}

1 个答案:

答案 0 :(得分:0)

更改

Session["User"] =  lblMessage.Text;

lblMessage.Text = Session["User"];

在你的第二页......飞行员错误? :)