close

PageBase.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;


/// <summary>
/// PageBase 的摘要描述
/// </summary>
public class PageBase : System.Web.UI.Page
{

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 system redirects to login page now.!\n\n');

window.location.href='/login.aspx';

}

</script>";

ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script);

}

}

Web.config

<system.web>
<sessionState mode="InProc" timeout="1"/>
</system.web>

every page

public partial class _Default : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{

}
}

http://www.dotnetgallery.com/kb/resource9-how-to-do-auto-logout-and-redirect-to-login-page-when-session-expires-using.aspx

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 amychang2014 的頭像
    amychang2014

    工作需要筆記

    amychang2014 發表在 痞客邦 留言(0) 人氣()