2016-09-20 119 views
0

我需要在MVC中延长会话超时以维护用户会话。试图让global.asax中的Session_End延长会话,但它没有奏效。如何在ASP.Net MVC中的会话为空时延长会话时间?

+0

见http://stackoverflow.com/questions/21990619/how-to-increase-session-timeout-in-asp-net? –

+0

可以从javascipt/jquery扩展吗? –

+0

你的意思是,如果你的会话超时20分钟和15分钟过去,并在该会话超时重新设置20分钟右? –

回答

0

你必须呼叫控制器方法在特定的时间间隔根据您的要求重置会话超时通过这种方式您的应用程序集中在一定的时间间隔。

将您的jQuery代码布局

JQuery的:

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. 
} 
+0

你可以请更新我是否工作或不? –

1

试一试在你的web.config文件,
更改超时现在给出, 超时设置为60分钟

<configuration> 
... 
<system.web> 
<sessionState mode="InProc" timeout="60" /> 
</system.web> 
... 
</configuration>