• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1935
  • Last Modified:

Session Timeout Warn & redirect to login page

Hi All,

I'm expecting a solution in the asp.net to warn the user before the session expires due to the inactivity and still the session is inactive then it should redirect to login page. Please help me in implementing the solution.
SessionExpired-MessageWindow.PNG
0
learntechnology
Asked:
learntechnology
1 Solution
 
rajapandian_81Commented:
Hi,

You can use "setTimeout" function in javascript. You can set time in milliseconds. After that time the message will be prompted.
setTimeout(function() { if (confirm("Your session expired due to inactivity. Please click [OK] to login again.")) { window.location.href = "login.aspx" } }, 1200000);

Open in new window

0
 
Alan WarrenCommented:
Session.Timeout and Forms.Authentication.Timeout are two different animals, for these things to work as intended, both need to be in synch.
    ' Get the current Forms.Authentication.Timeout as a timespan
    ' The amount of time in minutes after which the authentication expires. 
    Dim currentFormsTimeout As System.TimeSpan = FormsAuthentication.Timeout

    ' Synch session timeout and forms timeout
    Session.Timeout = currentFormsTimeout.TotalMinutes

Open in new window

Then you can use something like this Preventing Session Timeouts in C# ASP .NET to extend the timeout period.

Alan
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
learntechnologyAuthor Commented:
Thanks everyone. Since Forms Time out & Session Timeout values are different. I tried using following lines of code. Below code redirects to the session expired page if the screen is inactive for 1 minute.

<meta http-equiv="refresh" content="0060; URL=/Account/SessionExpired.aspx" />
0
 
learntechnologyAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for learntechnology's comment #a38407592

for the following reason:

Since other solutions are not feasible to the requirement. I have implemented the following code after thorough analysis and testing.<br /><br />&lt;meta http-equiv=&quot;refresh&quot; content=&quot;0060; URL=/Account/SessionExpire<wbr />d.aspx&quot; /&gt;
0
 
learntechnologyAuthor Commented:
Since my solution is feasible after testing, i'm comfortable to close this request. If anyone has better solution than this with simple code, i would be happy to accept that solution.
0
 
learntechnologyAuthor Commented:
Below code redirects to the session expired page if the screen is inactive for 1 minute.

<meta http-equiv="refresh" content="0060; URL=/Account/SessionExpired.aspx" />

Above code works good after testing.
0
 
learntechnologyAuthor Commented:
Since my solution is feasible after testing, i'm comfortable to close this request. If anyone has better solution than this with simple code, i would be happy to accept that solution.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now