Automatically redirect User to Login page after Session Timeout in ASP.Net
SessionTimeout.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionTimeout.aspx.cs" Inherits="SessionTimeout" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html>
SessionTimeout.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class SessionTimeout : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); AutoRedirect(); } public void AutoRedirect() { int int_MilliSecondsTimeOut = (this.Session.Timeout * 60000); string str_Script = @" <script type='text/javascript'> intervalset = window.setInterval('Redirect()'," + int_MilliSecondsTimeOut.ToString() + @"); function Redirect() { alert('Your session has been expired and you will redirects to Login pagenn'); window.location.href='/login.aspx'; } </script>"; ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script); } }
(Visited 7 times, 1 visits today)