如何在ASP.Net C中销毁Session变量# [英] How to destroy Session variables in ASP.Net C#

查看:113
本文介绍了如何在ASP.Net C中销毁Session变量#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个奇怪的问题,我使用一些会话变量并试图使用代码销毁那些

I face a strange problem, I use some session variable and try to destroy those using the code

Session.Contents.RemoveAll()



工作正常,但突然停止工作,就是它无法破坏我的会话变量。我不知道我的错是什么。请帮助我。


It was work fine but suddenly it stop working, that is It cannot destroy my session variable. I don't know what's my fault. please help my.

推荐答案

Sazzad说:

就是它无法破坏我的会话变量

that is It cannot destroy my session variable



我不确定您的问题的性质,因为您提供的细节太少,但是,

您声明要破坏会话,在这种情况下,我建议你使用


I am not sure about the nature of your problem, as you provided too few details, however,
you stated that you want to destroy the session, in which case I would suggest that you use

Session.Abandon();





注意:调用此方法时,在处理完当前页面上的所有脚本之前,不会删除当前的Session对象。这意味着可以在与Abandon的调用相同的页面上访问会话变量,但不能从另一个Web页面访问。



干杯,

Edo



Note: When this method is called, the current Session object is not deleted until all of the script on the current page have been processed. This means that it is possible to access session variables on the same page as the call to Abandon, but not from another Web page.

Cheers,
Edo


session.Clear();

session.Abdomen();
session.Clear();
session.Abdomen();


尝试使用 Session.Clear() Session.Abandon(); 两者之间的区别是



清除从会话状态集合中删除所有键和值。



放弃删除会话中存储的所有对象。如果你没有明确地调用Abandon方法,服务器会删除这些对象并在会话超时时销毁会话。

它还会引发Session_End等事件。



问候..:)
Try using Session.Clear() or Session.Abandon(); The difference between the two is

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.
It also raises events like Session_End.

Regards..:)


这篇关于如何在ASP.Net C中销毁Session变量#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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