如何清除会议 [英] How to clear the Session

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

问题描述

在我的项目中,我有4个会话用户名,finyear,company,branch

当加载选择公司表格时,我想清除除用户名之外的所有会话.怎么做?

我在page_load中使用以下方法来选择公司表格,但显示错误
``对象引用未设置为对象的实例''

In my project I have 4 Sessions username,finyear,company,branch

when select company form is loading, I want to clear the all the sessions except username. How to do it?

I am using following in page_load for select company form, but the errror display
''object reference is not set to an instance of an object''

Session.Remove("name")
Session.Contents.Remove("name")
Session.Abondon()
Session.Clear()



请任何人帮助我

谢谢



Please anybody help me

Thank you

推荐答案

像这样:

like this:

foreach (string key in Session.Keys)
{
    if("username" != Session[key])
    {
        Session.Remove(Session[key]);
    }
}


Session["finyear"] = null;
Session["company"] = null;
Session["branch"] = null;


报价:

您可以使用
Session ["finyear"] = null;
会话[公司"] = null;
Session ["branch"] = null;

you can use
Session["finyear"] = null;
Session["company"] = null;
Session["branch"] = null;


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

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