gpt4 book ai didi

c# - 强制 session 开始

转载 作者:行者123 更新时间:2023-11-30 14:37:19 26 4
gpt4 key购买 nike

每次我的应用程序以开发模式运行时,如何强制调用 global.asax 上的 Session_Start 方法?

我有一些代码需要调试,但有时会被调用,有时不会。我已经尝试关闭“ASP.NET 开发服务器”,但没有成功。

最佳答案

查看这篇文章 http://sandblogaspnet.blogspot.com/2008/03/methods-in-globalasax.html

Session start event is fired only when a new session for a user starts. Once “Session_Start” for a user is fired then if the user makes subsequent request to any resource within the application this event is not at all triggered. The event is triggered only when the user’s session expires and then the user tries to access any resource in the application again.

您确定您不是在寻找 Application_Start 吗?如果不是,那么只要您重置 session ,就应该调用该事件。

编辑:另请查看这篇关于试图与您做同样事情的人的文章 http://forums.asp.net/t/1608241.aspx/1

从那个页面:

You are right I just tested it by putting <sessionState timeout="1"/> in my Web.config file. Then I waited 1 minute and clicked on a link on the page. It immediately went back into Session_Start and re-authenticated the user.

编辑 2:尝试从起始页调用 Session.Abandon()。它应该删除 session 并要求用户启动一个新 session 。

关于c# - 强制 session 开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9380309/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com