4

I have my session timeout set to 1 in web.config. I wanted to check whether session start and end occurs as expected, so I had this in my 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.

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.

Pallavi
  • 544
  • 6
  • 15

1 Answers1

4

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 is called when the session ends - normally 20 minutes after the last request (for example if browser is inactive or closed). 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.

Community
  • 1
  • 1
Scott Perham
  • 2,410
  • 1
  • 10
  • 20