Tuesday, January 23, 2018

Redirect to login page if Idle Timeout is 10mins

MVC

The Following javascript file put in Layout Page(Views/Shared/_layout.cshtml ) on MVC page.

<script type="text/javascript">
        rootUrl = '@Url.Content("~/")';
        var t;
        window.onload = resetTimer;
        document.onkeypress = resetTimer;

        function logout() {
           // alert("You are now logged out.")
            // location.href = 'Logoff.php'
            window.location.href = '@Url.Action("Login", "Register")';

        }

        function resetTimer() {

            clearTimeout(t);
           // t = setTimeout(logout, 60000) //logs out in 1 min
         t = setTimeout(logout, 600000) //logs out in 10 min
        }


    </script>
================
Web Page(ASP.NET)

 The Following javascript file put on Master Page.(MasterPage.master) on ASP.NET Site

 <script type="text/javascript">
 var t;
        window.onload = resetTimer;
        document.onkeypress = resetTimer;

        function logout() {
            // alert("You are now logged out.")
            // location.href = 'Logoff.php'
            //window.location.origin : you'll get http://sub.domain.com *****
            window.location.href = window.location.origin+"/Account/login";

        }

        function resetTimer() {
            clearTimeout(t);
         //   t = setTimeout(logout, 60000) //logs out in 1 min
             t = setTimeout(logout, 600000) //logs out in 10 min

        }
    </script>

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...