代码之家  ›  专栏  ›  技术社区  ›  padh

如何在ASP中会话为空时延长会话时间。净MVC?

  •  0
  • padh  · 技术社区  · 8 年前

    我需要在MVC中延长会话超时以维护用户会话。尝试在上扩展会话 Session_End 在全球范围内。asax,但没有成功。

    2 回复  |  直到 8 年前
        1
  •  1
  •   Vinu Davis    8 年前

    在您的网络中尝试此功能。配置文件,
    更改给定的超时, 现在超时设置为60分钟

    <configuration>
     ...
    <system.web>
    <sessionState mode="InProc" timeout="60" />
    </system.web>
     ...
    </configuration>
    
        2
  •  0
  •   Sandip - Frontend Developer    8 年前

    你必须这么做 在特定时间间隔调用控制器方法 根据您重置会话超时的要求,通过这种方式,您的应用程序将注意力集中在某个时间间隔上。

    将JQuery代码放置在布局中

    J查询:

    var RefreshSessionInterval;
    
    $(document).ready(function () {        
          clearInterval(RefreshSessionInterval);
          RefreshSessionInterval = setInterval("RefreshSession()", 30000);  // change your interval time as per requirement     
    });
    
    function RefreshSession() {
           $.ajax({
                type: "POST",
                url: '@Url.Action("RefreshSession", "YourControllerName")',           
                success: function (data) {               
                },
                error: function () {
                }
           }); 
    }
    

    控制器:

    Public void RefreshSession()
    {
        //your session reset from this line, as i know you don't have to write any code here.
    }