我在哪里清除会话值? [英] Where do I clear the session value?

查看:59
本文介绍了我在哪里清除会话值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将EmployeeIds存储在会话变量中,然后单击按钮,该按钮根据存储在会话变量中的EmployeeIds生成特定员工的报告.但是,当我返回单击该按钮的位置并第二次单击该按钮时,没有任何选择的EmployeeIds报告向我显示了先前选择的EmployeeIds记录的所有报告.现在我必须在哪里清除会话?还是有其他想法可以将EmployeeIds传递到另一页并在返回上一页或重定向到另一页时清除其值?请不要建议我使用QueryString,而不必使用它.

解决方案

使用Session.AbandonSession.Clear().

尝试:

 受保护的  void  btnLogout_Click(对象发​​件人,EventArgs e)
    {
        // 清除会话变量
        会话[" ] = " ";
        会话[" ] = " ";
        会话[" ] = " ";
        // 重定向到索引页面
        Response.Redirect(" );
    } 


请参阅:本文 [ ^ ]


在第一页的页面加载中.如果不回发,请检查该会话变量是否存在并将其删除.

 Session.Remove(" ); 


因此,每当返回上一页时,此会话变量都将被删除.


I store the EmployeeIds in the session variable and click the button which generate the report of the particular Employees depending on the EmployeeIds stored in session variable. But when I go back where I clicked the button and second time click the button without any selecting EmployeeIds report show me all the report previously selected EmployeeIds records. Now where I have to clear the session? Or any other idea to pass the EmployeeIds to another page and clear it''s value when go back to previous page or redirect to other page? Please don''t suggest me to use QueryString I don''t have to use it.

解决方案

Use either Session.Abandon or Session.Clear().


Try this:

protected void btnLogout_Click(object sender, EventArgs e)
    {
        //clear session variables
        Session["Name"] = "";
        Session["Address"] = "";
        Session["Phone"] = "";
        //redirect to index page
        Response.Redirect("index.aspx");
    }


Refer: this article[^]


In page load of first page. if its not postback check whether that session variable exists and delete it.

Session.Remove("varName");


so whenever its going back to previous page, this session variable will be removed.


这篇关于我在哪里清除会话值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆