I am using custom implementation of microsoft asp.net identity because i have custom tables that is why i have given custom implementation of all my methods IUserStore a
call controller method at specific time interval so it will reset session timeout on evry call. For example if initially you have set your session timeout at 30 min and after 20 min you call this action, it will reset session timeout to again 30 min, by this way your session remains active even reach 30 min after login.
Place your JQuery code in layout
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 () {
}
});
}
Controller:
Public void RefreshSession()
{
//your session reset from this line, as i know you don't have to write any code here.
}
public bool LogOut()
{
LogOff();
return true;
}
void LogOut()
{
Session.Clear();
Session.Abandon();
Session.RemoveAll();
ClearCache();
}
void ClearCache()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
////FormsAuthentication.SignOut();
}