如何在asp.net mvc中重置会话超时

Dev*_*per 5 javascript asp.net asp.net-mvc session jquery

我想在用户仍处于活动状态时重置会话超时.

  1. 在我的场景中,我的会话超时为20分钟,当在10秒之前达到会话时间时,我显示一个对话框,确认用户为"会话将要超时,你想留在吗?".如果用户单击是,我想继续我的会话再次从第21分钟开始20分钟,因为根据要求我在数据库表中保存用户会话时间.

  2. 我们可以设置会话超时的计时器.

所以,请帮助我任何人,如何重置会话超时?

San*_*jay 9

编写jQuery脚本,如:

 (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);
    }
Run Code Online (Sandbox Code Playgroud)

和控制器中的添加操作方法,如:

  public ActionResult SessionTimeout()
    {

        Session.Timeout = Session.Timeout + 20;

        return Json("",JsonRequestBehavior.AllowGet);
    }
Run Code Online (Sandbox Code Playgroud)

希望以上技术可以帮到你.