Link to home
Start Free TrialLog in
Avatar of learntechnology
learntechnologyFlag for United States of America

asked on

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
Avatar of rajapandian_81
rajapandian_81
Flag of India image

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

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
ASKER CERTIFIED SOLUTION
Avatar of learntechnology
learntechnology
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of learntechnology

ASKER

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;
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.
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.
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.