You can't transfer when the session ends because that happens when the user is no longer connected to the server. If you're setting a session variable for login purposes (never roll your own mechanisms, always use a standard membership/security system).
Check for the session variable and if it's null, just Response.Redirect to the session timeout page.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
You can't transfer when the session ends because that happens when the user is no longer connected to the server. If you're setting a session variable for login purposes (never roll your own mechanisms, always use a standard membership/security system).
Check for the session variable and if it's null, just Response.Redirect to the session timeout page.
Well the session has expired and it errors out.
So is there a away to redirect without a session? I was thinking server.transfer would work.
"So is there a away to redirect without a session? I was thinking server.transfer would work."
To redirect when? Server.Transfer behaves differently from Response.Redirect, but both have the requirement that the user's browser be connected to the server to get the result of the transfer, or the instruction to redirect. They both occur during the
processing of a page lifecycle.
You can't do anything when session expires, but you can check to see if session has expired when the user tries to do something else (once again contacts the server).
What is it that "errors out"? Are you getting a NullReferenceException because you try to access a Session variable that no longer exists? If so, you should always test for null before you work with session variables. Remember - sessions can be lost unexpectedly
for other reasons - not just because they timed out. Never assume that a session variable exists. Always check for null first.
Participant
995 Points
2616 Posts
Web forms redirect when session expires
Oct 27, 2018 01:26 AM|tvb2727|LINK
I need to redirect to a session expired page when my session is over.
I do not have forms authentication, so I can't use that code.
I tried Server.Transfer(), but it receives a null reference.
How can I accomplish this?
All-Star
26021 Points
5875 Posts
Re: Web forms redirect when session expires
Oct 27, 2018 02:28 PM|markfitzme|LINK
You can't transfer when the session ends because that happens when the user is no longer connected to the server. If you're setting a session variable for login purposes (never roll your own mechanisms, always use a standard membership/security system). Check for the session variable and if it's null, just Response.Redirect to the session timeout page.
Participant
995 Points
2616 Posts
Re: Web forms redirect when session expires
Nov 03, 2018 12:37 AM|tvb2727|LINK
Well the session has expired and it errors out.
So is there a away to redirect without a session? I was thinking server.transfer would work.
Contributor
4611 Points
1705 Posts
Re: Web forms redirect when session expires
Nov 05, 2018 04:30 AM|KathyW|LINK
"So is there a away to redirect without a session? I was thinking server.transfer would work."
To redirect when? Server.Transfer behaves differently from Response.Redirect, but both have the requirement that the user's browser be connected to the server to get the result of the transfer, or the instruction to redirect. They both occur during the processing of a page lifecycle.
Contributor
4611 Points
1705 Posts
Re: Web forms redirect when session expires
Nov 05, 2018 11:19 PM|KathyW|LINK
You can't do anything when session expires, but you can check to see if session has expired when the user tries to do something else (once again contacts the server).
See the following article, for example: http://www.nullskull.com/a/1630/build-an-aspnet-session-timeout-redirect-control.aspx If you are not using Forms Authentication, just skip those lines.
Member
204 Points
769 Posts
Re: Web forms redirect when session expires
Nov 07, 2018 07:39 AM|tahazubairahmed|LINK
Use below code in your master page code file.
Taha Zubair Ahmed
http://www.tahazubair.blogspot.com
All-Star
187702 Points
27196 Posts
Moderator
Re: Web forms redirect when session expires
Nov 07, 2018 07:52 AM|Mikesdotnetting|LINK
ASP.NET Tutorials | Learn Entity Framework Core | Learn Razor Pages