ASP.Net Session_Start 总是触发
我对以下内容有点困惑: 我在 Global.asx 的 Session_Start() 中设置了一个带有一些逻辑的 asp.net 网站。我预计这甚至只会在会话期间触发一次。然而,每个请求都会触发该事件。
当我声明一个虚拟会话对象时,这解决了问题。 另外,当我在 web.config 中添加
时,我可以解决此问题。我使用 IIS7,并检查了默认值,它已设置为“正在处理”。
我缺少什么吗?这是正常行为吗?即使我没有声明会话对象,我也希望这个事件能够起作用。
I am a bit confused about the following:
I set up an asp.net Website with some logic in the Session_Start() of the Global.asx. I expected that this even will only trigger once during a session. However the event fired with every single request.
When I declare a dummy session object this fixed the problem.
Also I can fix this problem when I add <sessionState mode="InProc" />
in the web.config. I use IIS7 and I checked the default value and this is already set to "In Process".
I am missing something? Is this normal behaviour? I was expecting this event to work even if I don't declare a session object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将某些内容存储在 Session 对象中。
http://blogs.msdn.com/b/nikhiln/archive/2007/06/21/detecting-session-timeout-in-asp-net-2-0-web-applications.aspx
Store something in a Session object.
http://blogs.msdn.com/b/nikhiln/archive/2007/06/21/detecting-session-timeout-in-asp-net-2-0-web-applications.aspx
我认为如果所使用的浏览器不允许 cookie,就会发生这种情况。此外,如果您的应用程序池正在重新启动,会话将会丢失。
这将解决不允许 cookie 的问题。
I think this happens if the browser being used does not allow cookies. As well if you application pool is being restarted the session will be lost.
That will solve issues with cookies not being allowed..
您需要检查:
You'd check:
我最近遇到这个问题,发现如果 bin 文件夹内有任何文件更新,它会自动重新启动应用程序,从而触发 Application_Start 和 Session_Start 事件。就我而言,我在 bin 文件夹内创建日志文件,并在日志文件中更新重新启动应用程序。我只是将日志文件移到 bin 文件夹之外来解决问题。
I recently came across this issue and found that if any file is updated inside bin folder it automatically restart application which triggers Application_Start and Session_Start events. In my case i was creating log files inside bin folder and updates in log files restarts application. I simply moved my log files outside of bin folder to resolve issue.