当 Session.Abandon() 不起作用时,如何以编程方式结束 ASP.NET 中的会话?

发布于 2024-07-21 07:25:13 字数 83 浏览 8 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

因为看清所以看轻 2024-07-28 07:25:13

这很可能是因为您的 SessionMode 不是 InProc(唯一可以检测会话何时结束的模式)。

引自 MSDN

会话事件

ASP.NET 提供了两个事件来帮助
您管理用户会话。 这
Session_OnStart 事件在以下情况下引发:
新会话开始,并且
当会话发生时,会引发 Session_OnEnd 事件
会话被放弃或过期。
会话事件在
ASP.NET 的 Global.asax 文件
应用程序。

Session_OnEnd 事件不是
如果会话模式属性受支持
设置为 InProc 以外的值,
这是默认模式。

This is most likely because your SessionMode is not InProc (the only one that can detect when a session ends).

Quoted from MSDN:

Session Events

ASP.NET provides two events that help
you manage user sessions. The
Session_OnStart event is raised when a
new session starts, and the
Session_OnEnd event is raised when a
session is abandoned or expires.
Session events are specified in the
Global.asax file for an ASP.NET
application.

The Session_OnEnd event is not
supported if the session Mode property
is set to a value other than InProc,
which is the default mode.

只是我以为 2024-07-28 07:25:13

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 ).

庆幸我还是我 2024-07-28 07:25:13

您是否尝试过使用以下内容?

System.Web.Security.FormsAuthentication.SignOut();

这将清除用于表单身份验证的 cookie,尽管可能不是您想要的。

除了 Session.Abandon() 之外,您可能还需要使用它

Have you tried using the following?

System.Web.Security.FormsAuthentication.SignOut();

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()

⒈起吃苦の倖褔 2024-07-28 07:25:13

如果会话似乎持续存在,您可以尝试(在 web.config 中):

<sessionState regenerateExpiredSessionId="true">

If sessions appear to persist you might try (in web.config):

<sessionState regenerateExpiredSessionId="true">
梦醒灬来后我 2024-07-28 07:25:13

这取决于您的应用程序是否位于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文