定时器结束后如何强制用户注销? [英] How Do I Force A User To Logout After The Timer Ends?

查看:155
本文介绍了定时器结束后如何强制用户注销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和ASP.NET开发一个考试Web应用程序..我有不同的房间和用户将登录的每个房间,参加他的考试然后退出并移动到下一个房间参加考试的时间是每个房间需要7分钟...



i需要强制用户退出或者在7分钟后自动将其注销并重定向到登录页面我保证下一个用户将有一个新的会话考试..



我试图寻找一种可能的方法来做到这一点,但我只能找到一些东西喜欢强制用户注销,如果他是空闲或使用FormsAuthentication.SignOut方法()但我不知道该怎么做..



谢谢,

i'm developing an Exam web application using C# & ASP.NET.. i have different rooms & each room the user will log in, take his exam then logout & move to the next room the duration for taking the exam is 7 minutes for each room ...

i need to force the user to log out or just log him out automatically after 7 minutes & do a redirect to the Login page so i will guarantee that the next user will have a new session exam ..

I've tried to search for a possible way to do that but i can only find something like to force the user to logout if he is idle or to use the FormsAuthentication.SignOut Method () but i'm not sure how to do that..

Thanks,

推荐答案

试用此代码...





Try this Code...


<script language="javascript" type="text/javascript">
    //Session timeout in minute.
    var sessionTimeout = "<%= Session.Timeout %>";

    //Session timeout warning before 2 minute.
    var sessionTimeoutWarning = parseInt(sessionTimeout) - 2;

    //Session timeout in millisecond.
    var sTimeout = parseInt(sessionTimeout) * 60 * 1000;

    //setTimeout('SessionWarning()', sTimeout);

    setTimeout(' Redirect()', sTimeout);
    function SessionWarning() {
        //Calculating minutes before timeout in millisecond.
        var minutesForExpiry = (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));

        var message = "Your session will expire in another " + minutesForExpiry + " mins! Please refresh the page before the session expires";
        alert(message);

        setTimeout('Redirect()', (minutesForExpiry * 1000 * 60));

    }

    function Redirect() {
        var msg = "Session expired. You will be redirected to login page";
        alert(msg);
        window.location = "LoginPage.aspx";
    }
    
</script>


我找到了一种在会话到期后退出用户的很酷的方式,希望这会有所帮助。 />


I have found a cool way of logging out a user after session expiration, hope this helps.

Test time = 1min





在webconfig文件中将sessionState超时设置为所需时间(以分钟为单位)





In the webconfig file set sessionState timeout to desired time in minutes

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





使用Masterpages,将此Meta标记放在head部分。时间以秒为单位





Using Masterpages, place this Meta tag in the head section. Time is in seconds

<meta http-equiv="refresh" content="60; ">





在Master页面的Page_Load事件中,插入





In Page_Load event of Master page, insert

If Session("UserName") Is Nothing Then
        Response.Redirect("~/Login.aspx")
    End If


这篇关于定时器结束后如何强制用户注销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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