locked
check user authentication at intervals RRS feed

  • Question

  • User-2060576634 posted

    hi ..

    I want to check user authentication in certain intervals and redirect the user to login page if the user is not authenticated (or the session has timed out). how should i complete this code?

    <script type="text/javascript">
        setInterval(function () {
            // check user authentication and redirect if not autheticated
        }, 5000);
    </script>
    Friday, April 3, 2015 2:01 AM

Answers

  • User-166373564 posted

    Hi,

    i was hoping for a webmatrix/webpages solution.. not MVC

    According to your description above, if the user isn't initially unauthenticated, you can use the code below,

    <script type="text/javascript">
        setInterval(function () {
            var authenticated = @(WebSecurity.IsAuthenticated.ToString().ToLower());
            if (!authenticated) {
                location.href ='http://localhost:12718/Account/login';
            }
        }, 5000);
    </script>
    

    Best regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 7, 2015 10:38 PM

All replies

  • User1321972883 posted

    Hi !

    You can refer to the below mentioned code-

     setInterval(function () {
            var frmObj = $('#frmHomeReportForm');
            TF.get({
                url: "~/LoginStats/GetHomeList/", // Redirecting to the controller action method where you will check the User is Authenticated or Not and Session time
                serialize: frmObj,
                success: function (data) {                
                }
            });
        },5000);

     and in controller-

    if (HttpContext.Current.User.Identity.IsAuthenticated)
                    {
    
                        //Redirect to Default page
                    }
                    else
                    {
                        //Redirect to  Message/error/session time out page
                    }

    Hope this will help you.

    Friday, April 3, 2015 2:18 AM
  • User-2060576634 posted

    i was hoping for a webmatrix/webpages solution.. not MVC

    Friday, April 3, 2015 2:23 AM
  • User-166373564 posted

    Hi,

    i was hoping for a webmatrix/webpages solution.. not MVC

    According to your description above, if the user isn't initially unauthenticated, you can use the code below,

    <script type="text/javascript">
        setInterval(function () {
            var authenticated = @(WebSecurity.IsAuthenticated.ToString().ToLower());
            if (!authenticated) {
                location.href ='http://localhost:12718/Account/login';
            }
        }, 5000);
    </script>
    

    Best regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 7, 2015 10:38 PM