ASP.Net MVC 中会话为空时如何延长会话时间?
How to extend the session time when session empty in ASP.Net MVC?
我需要延长 MVC 中的会话超时以维持用户会话。试图在 global.asax 的 Session_End
上延长会话,但没有成功。
你必须在特定的时间间隔调用控制器方法根据你的要求重置会话超时,这样你的应用程序就会专注于某个时间间隔。
将您的 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.
}
在你的 Web.config 文件中试试这个,
更改给定的超时,
现在超时设置为 60 分钟
<configuration>
...
<system.web>
<sessionState mode="InProc" timeout="60" />
</system.web>
...
</configuration>
我需要延长 MVC 中的会话超时以维持用户会话。试图在 global.asax 的 Session_End
上延长会话,但没有成功。
你必须在特定的时间间隔调用控制器方法根据你的要求重置会话超时,这样你的应用程序就会专注于某个时间间隔。
将您的 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.
}
在你的 Web.config 文件中试试这个,
更改给定的超时,
现在超时设置为 60 分钟
<configuration>
...
<system.web>
<sessionState mode="InProc" timeout="60" />
</system.web>
...
</configuration>