Redirecting to another page from Session_end in global.asax

2.3k Views Asked by At

I need to redirect the user to the login page on session timeout. The issues with Session_End method in the global.asax are:

  1. It does not support Response.Redirect or Server.Transfer
  2. Any attempt to use HttpContext.Current.Response results in 'Object Reference not set to an instance of an object' error
The second error is understandable since on session time out, the current session would be terminated and set to null.
What I want to know is whether is it possible to redirect the user directly (and specifically) from session_end to another page. There are methods which work (not using the session_end method), but all of them require a request to the server(such as a refresh,which I don't want). Can i do this without using javascript?(more important, should I?)
Thanks in advance!

1

There are 1 best solutions below

2
Axarydax On

Isn't Session_End raised directly on server, without any interaction from user?

What happens, when I go to your page (and start a session), close browser window and never return? Then it's understandable, that HttpContext.Current.Response is null.