会话超时呼叫和重定向 [英] Session Time Out Call and Redirect

查看:91
本文介绍了会话超时呼叫和重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.Net framework 3.5创建Web应用程序,我实现了asp.net成员资格(Forms Authentication),现在,我想要的是当用户会话状态处于非活动状态然后将页面重定向到Lockscreen.aspx然后用户将输入详细信息并继续工作。经过大量的搜索我得到的东西是



 Web配置
< sessionState mode = InProc timeout = 2 />

< authentication mode = Forms >
< forms defaultUrl = 〜/ Pages / Default。 aspx
loginUrl = 〜/ Pages / Login.aspx超时= 2
/>
< / 身份验证 >





我正在配置会话超时,因为会话超时然后用户应该得到警报,如果用户没有响应,那么重定向到锁屏.aspx



 Default.aspx 

函数SessionExpireAlert(超时){
var seconds = timeout / 1000 ;
alert(秒);
document.getElementsByName( secondsIdle)。innerHTML = seconds;
document.getElementsByName( seconds)。innerHTML = seconds;
setInterval(function(){
seconds--;
document.getElementById( )。innerHTML =秒;
document.getElementById( secondsIdle)。innerHTML =秒;
}, 1000 );
setTimeout(function(){
// 在超时20秒之前显示弹出窗口。
$ find( mpeTimeout)。show();
},timeout - 20 * 1000 );
setTimeout(function(){
window.location = LockScreen.aspx;
},超时);
}

函数ResetSession(){
// 重定向到刷新会话。
window.location = window.location.href;
}





 Defualt.aspx.cs 

回复.Cache.SetCacheability(HttpCacheability.NoCache);
if (!this.IsPostBack)
{
Session [ 重置] = true ;
配置config = WebConfigurationManager.OpenWebConfiguration( 〜/ Web.Config);
SessionStateSection section =(SessionStateSection)config.GetSection( system.web / sessionState) ;
int timeout =( int )section.Timeout.TotalMinutes * 1000 * 60 ;
ClientScript.RegisterStartupScript( this .GetType(), SessionAlert SessionExpireAlert( + timeout + ); true );
}





现在问题是当用户会话仍处于活动时会发生会话超时警报。我不希望这种情况发生.Alert应该在会话过期/超时时出现。

解决方案

find( mpeTimeout)。show();
},超时 - 20 * 1000 );
setTimeout(function(){
window.location = LockScreen.aspx;
},超时);
}

函数ResetSession(){
// 重定向到刷新会话。
window.location = window.location.href;
}





 Defualt.aspx.cs 

回复.Cache.SetCacheability(HttpCacheability.NoCache);
if (!this.IsPostBack)
{
Session [ 重置] = true ;
配置config = WebConfigurationManager.OpenWebConfiguration( 〜/ Web.Config);
SessionStateSection section =(SessionStateSection)config.GetSection( system.web / sessionState) ;
int timeout =( int )section.Timeout.TotalMinutes * 1000 * 60 ;
ClientScript.RegisterStartupScript( this .GetType(), SessionAlert SessionExpireAlert( + timeout + ); true );
}





现在问题是当用户会话仍处于活动时会发生会话超时警报。我不希望这种情况发生.Alert应该在会话过期/超时时出现。


你需要在每次回发时重置计时器,请查看以下文章:在ASP.NET中使用jQuery的消息超时警告消息 [< a href =http://www.codeproject.com/Articles/711196/Session-Time-Out-Warning-Message-Using-jQuery-in-Atarget =_ blanktitle =New Window> ^

I am creating web application using .Net framework 3.5, I implemented asp.net membership (Forms Authentication), Now, What i want is when user session state is inactive then redirect page to Lockscreen.aspx and then user will enter details and continue work. After lot of search I have got something is

Web config
<sessionState mode="InProc"  timeout="2"/>

<authentication mode="Forms">
      <forms defaultUrl="~/Pages/Default.aspx"
          loginUrl="~/Pages/Login.aspx" timeout="2"
          />
    </authentication>



I am configuring session timeout as when session timeout then user should get alert and if user doesn't respond then redirect to lockscreen.aspx

Default.aspx

function SessionExpireAlert(timeout) {
            var seconds = timeout / 1000;
            alert(seconds);
            document.getElementsByName("secondsIdle").innerHTML = seconds;
            document.getElementsByName("seconds").innerHTML = seconds;
            setInterval(function () {
                seconds--;
                document.getElementById("seconds").innerHTML = seconds;
                document.getElementById("secondsIdle").innerHTML = seconds;
            }, 1000);
            setTimeout(function () {
                //Show Popup before 20 seconds of timeout.
                $find("mpeTimeout").show();
            }, timeout - 20 * 1000);
            setTimeout(function () {
                window.location = "LockScreen.aspx";
            }, timeout);
        }

        function ResetSession() {
            //Redirect to refresh Session.
            window.location = window.location.href;
        }



Defualt.aspx.cs

            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            if (!this.IsPostBack)
            {
                Session["Reset"] = true;
                Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
                SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
                int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
                ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
            }



Now problem is when user session is still active session timeout alert occur's . I don't want that to be happen .Alert should appear when session is expired/timeout.

解决方案

find("mpeTimeout").show(); }, timeout - 20 * 1000); setTimeout(function () { window.location = "LockScreen.aspx"; }, timeout); } function ResetSession() { //Redirect to refresh Session. window.location = window.location.href; }



Defualt.aspx.cs

            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            if (!this.IsPostBack)
            {
                Session["Reset"] = true;
                Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
                SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
                int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
                ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
            }



Now problem is when user session is still active session timeout alert occur's . I don't want that to be happen .Alert should appear when session is expired/timeout.


you need to reset the timer on every postback, check below article : Session Time Out Warning Message Using jQuery in ASP.NET[^]


这篇关于会话超时呼叫和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆