2016-09-20 116 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>