当 Session.Abandon() 不起作用时,如何以编程方式结束 ASP.NET 中的会话?
Session.Abandon() 似乎没有做任何事情。 您可能希望在调用 Session.Abandon() 时触发 Session_end 事件。
Session.Abandon() doesn't seem to do anything. You would expect the Session_end event to fire when Session.Abandon() is called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这很可能是因为您的
SessionMode
不是InProc
(唯一可以检测会话何时结束的模式)。引自 MSDN:
This is most likely because your
SessionMode
is notInProc
(the only one that can detect when a session ends).Quoted from MSDN:
Session.Abandon() 是结束会话的方法。 您遇到的问题是什么?
如果其“后退”按钮相关,则这是一个完全不同的问题(页面不会在“后退”上回发,而是从客户端缓存运行一个,因此不会执行服务器端方法)。
此外,Session_End 也是有问题的。 当使用 InProc 会话时,它只会在 Session.Abandon() 上触发,因此如果您使用不同的 Session 模式,则不能依赖它。 否则,当达到 SessionTimeout 时,Session_End 将触发(我相信默认值为 20 分钟,在 Web.Config 中配置)。
Session.Abandon() is the way to end a session. What is the problem you are encountering?
If its Back button related, that is a completely different issue ( page doesn't postback on Back, instead it runs one from clientside cache so no server side methods will execute).
Additionally, Session_End is problematic. It will only fire on Session.Abandon() when using InProc sessions, so if you are using a different Session mode, it cannot be relied on. Otherwise, Session_End will fire when SessionTimeout is reached ( default is 20 minutes I believe, configured in Web.Config ).
您是否尝试过使用以下内容?
这将清除用于表单身份验证的 cookie,尽管可能不是您想要的。
除了 Session.Abandon() 之外,您可能还需要使用它
Have you tried using the following?
This will clear cookies used for form authentication, although may not be what you're looking for.
You may need to use this in addtion to Session.Abandon()
如果会话似乎持续存在,您可以尝试(在 web.config 中):
If sessions appear to persist you might try (in web.config):
这取决于您的应用程序是否位于 2 个服务器上:1 个具有自己的会话的 Web 应用程序,以及第二个也具有自己的会话的 WS 或 WCF 应用程序,它在我曾经工作过的应用程序中的情况如何。 如果遇到这种情况,会话必须在第二点结束,第一个点结束时会出现超时。 至少您必须使用令牌并保留活动会话的令牌列表。 也许这就是你的情况。 祝你好运。 附言。 要终止会话,请在第二台服务器中管理它。
It depends, if you have your application at 2 servers: 1 WebApplication that has its own session, and the second WS or WCF application that also has its own session, how it was in an application on which I was working once. Than if you have this case, the session must be ended at second point, and the first is ended the timeout appears. At least you'll have to use a token and to keep the list of tokens, of active sessions. May be it is your case. good luck. PS. To kill the session manage it in the second server.