Click here to Skip to main content
15,904,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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,
Posted
Updated 16-Nov-18 2:45am
Comments
Sergey Alexandrovich Kryukov 30-Dec-15 0:46am    
Bad idea. Instead, simply stop counting reserved time for an answer. But let me tell you: such exams is one of the factors which turned education into total trash.
—SA
Sinisa Hajnal 30-Dec-15 3:44am    
Don't sign him out...that is just bad user experience. Imagine if you went to work and had to logout / login to go to restroom, restaurant, to see your boss etc...

Instead, stop the counter, disable/close the room and point the user to the next one. Why does it need to be new session? And even if it is (that is, you close the old session), you can sign the user in automatically again.

You have to rethink / redesign the system.

Try this Code...


C#
<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>
 
Share this answer
 
I have found a cool way of logging out a user after session expiration, hope this helps.

Test time = 1min


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

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


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

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


In Page_Load event of Master page, insert

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900