简体   繁体   English

在C#中测试会话超时

[英]Testing session timeout in C#

I have my session timeout set to 1 in web.config. 我在web.config中将会话超时设置为1。 I wanted to check whether session start and end occurs as expected, so I had this in my global.asax.cs- 我想检查会话开始和结束是否按预期发生,所以我在global.asax.cs-中有这个

//In Session_Start
Response.Write("<script>alert('session started');</script>");
//In Session_End
Response.Write("<script>alert('session ended');</script>");

I get the alert when session starts but not when it ends. 我在会话开始时收到警报但在结束时没有收到警报。 When I put breakpoints, I see that the line is executed in Session_End but there is no alert on the screen. 当我放置断点时,我看到该行在Session_End中执行但屏幕上没有警报。

This is my first time working with sessions and even though I was able to test the functions another way, I am curious why it did not show the alert. 这是我第一次使用会话,即使我能够以另一种方式测试功能,我很好奇为什么它没有显示警报。

Thanks in advance. 提前致谢。

I know you are looking to write to the response and not redirect but have a look at this: Redirecting to another page on Session_end event another-page-on-session-end-event 我知道您正在寻求写入响应而不是重定向,但看看这个: 重定向到Session_end事件上的另一个页面另一个页面在会话结束事件

Session_End is called when the session ends - normally 20 minutes after the last request (for example if browser is inactive or closed). 会话结束时调用Session_End - 通常在最后一次请求后20分钟(例如,如果浏览器处于非活动状态或关闭状态)。 Since there is no request there is also no response. 由于没有请求,也没有回应。

This would strongly suggest that you cannot write to the response... because there isn't one. 这强烈建议你不能写回复...因为没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM