如何清除会话变量? [英] how to clear the session variable?

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

问题描述

亲爱的,



我用c#语言使用Asp.net vs2010。我将用户登录ID存储在Session中以读取其他页面中的值,它正常工作但现在我需要在重定向到登录页面后清除会话变量。

我正在使用以下代码存储Variable.Any一个帮助我如何做。



会话[EmpId] = txtUsername.Text;

会话[ EmpPwd] = txtPassword.Text;





谢谢提前!

Dear All,

I am using Asp.net vs2010 with c# language. I store the user login Id in Session for read the Value in some other Page it is working fine but now my need is clear the session variable after redirect to the login page.
I am using following Code for store the Variable.Any one help me how to do it.

Session["EmpId"] = txtUsername.Text;
Session["EmpPwd"] = txtPassword.Text;


Thanks advance!

推荐答案

在重定向的页面上写下此代码,

Write this code on the redirected page,
Session["EmpId"] = null;
Session["EmpPwd"] = null;
//or
Session.Clear();
Session.Abandon();



清除() - 从会话中删除所有键和值-state collection。

Abandon() - 删除会话中存储的所有对象。如果您没有显式调用Abandon方法,服务器会在会话超时时删除这些对象并销毁会话。



-KR


Clear() - Removes all keys and values from the session-state collection.
Abandon() - Removes all the objects stored in a Session. If you do not call the Abandon method explicitly, the server removes these objects and destroys the session when the session times out.

-KR

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

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