 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 24th, 2006, 01:59 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
ASP.NET Session End Redirect
Hi,
I have tried to automatically redirect by application to return back to my login page when session end by putting a redirect code in global session_end method, but it does not redirect even though the method was called. How would I redirect to another page automatically when session expired?
Thank you,
Peter
Peter
__________________
Peter
|
|

February 24th, 2006, 02:44 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can't. Period.
SessionEnd is never associated with a request; it fires at the server without a browser / client context. There is no way to redirect a client from the End event, because there is no client.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

February 24th, 2006, 02:51 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So, there is no other way except using timer or JavaScript which is not neccesary synchronize with SESSION state?
Peter
|
|

February 25th, 2006, 05:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you want to redirect to Login.aspx when the session has expired, can't you just always redirect to the Login page when the user hasn't logged in?
In addition to that, you can set a cookie that the user has previously logged in and use that cookie to determine where to redirect when they start a new session.
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

February 27th, 2006, 03:31 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, you are correct if you use cookie as you mention or check for session count in Global Global_AcquireRequestState event. Nonetheless, this require user intervention. In another word, when the session or cookie expired, the page doesn't redirect until user refresh the page or do something to the page. What I would like is the page to expire or redirect automatically without any user action. I was able to redirect by using javascript.
Peter
|
|

February 27th, 2006, 04:55 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
True. But to make it even simpler, you can add an HTML <meta> refresh tag to the page. If you set the refresh period to just under or over your session timeout (depending on whether you want to keep the session alive, or want to redirect to the Login page directly after a session timeout) the browser automatically takes the user to the requested page after a certain amount of time.
I think the "Thank you for your contribution" page that I am about to see when I click Post New Reply in a few seconds uses that technique....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

February 27th, 2006, 04:57 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Good point. Thanks Imar for your input.
Peter
|
|

February 27th, 2006, 05:00 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're welcome.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |