Shubhang
Shubhang

Reputation: 297

Redirecting to another page from Session_end in global.asax

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!

Upvotes: 1

Views: 2423

Answers (1)

Axarydax
Axarydax

Reputation: 16623

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.

Upvotes: 1

Related Questions