最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Reset Session Timeout in asp.net mvc - Stack Overflow

programmeradmin3浏览0评论

I want to Reset Session Timeout when user is still active.

  1. In my scenario my session timeout is 20 min., when session time is reached before 10 seconds i am showing a dialog to confirm the user as "Session is going to time out, Do you want to stay in ??". If user is click yes, i want to continue my session with again 20 minutes start from 21st minute, because as per requirement i am saving user session time in database table.

  2. can we set timer for session timeout.

So, Please help me anyone, how to reset session timeout??

I want to Reset Session Timeout when user is still active.

  1. In my scenario my session timeout is 20 min., when session time is reached before 10 seconds i am showing a dialog to confirm the user as "Session is going to time out, Do you want to stay in ??". If user is click yes, i want to continue my session with again 20 minutes start from 21st minute, because as per requirement i am saving user session time in database table.

  2. can we set timer for session timeout.

So, Please help me anyone, how to reset session timeout??

Share Improve this question edited Jul 17, 2014 at 4:49 Developer asked Jul 14, 2014 at 11:17 DeveloperDeveloper 8885 gold badges18 silver badges46 bronze badges 2
  • 1 Look at this pascarello./AjaxSessionTimer.aspx – Sanjay Commented Jul 14, 2014 at 12:09
  • You want a 10 minutes timeout, then a 20 minute timeout starting from the 21th minute??? – IEatBagels Commented Jul 16, 2014 at 13:25
Add a ment  | 

1 Answer 1

Reset to default 12 +50

Write the jQuery script like:

 (document).ready(function () {


        $("#divdialog").dialog({
            autoOpen: false,

            resizable: false,
            modal: true,
            title: "Session Timeout",

            buttons: {
                Yes: function () {
                    $.ajax({
                        url: '/<your controller>/SessionTimeout', // Redirects to action method for every 20 minutes.

                        dataType: "json",
                        type: "GET",
                        error: function () {
                            alert(" An error occurred.");
                        },
                        success: function (data) {
                            $("#divdialog").dialog('close');
                            display("stop");

                        }
                    });
                },
                Logout: function () {
                    location.href = '/<your controller>/Logout';
                }
            }
        });


    });

    function myFunction() { // Fires every 20 minutes

        setInterval(function () {
            $("#divdialog").dialog('open');

        }, 1200000);
    }

and Add Action Method in your controller like:

  public ActionResult SessionTimeout()
    {

        Session.Timeout = Session.Timeout + 20;

        return Json("",JsonRequestBehavior.AllowGet);
    }

Hope above technique helps you.

发布评论

评论列表(0)

  1. 暂无评论