뭔가 :
public class YourController : Controller {
public ActionResult TheAction() {
ViewData["SessionTimeout"] = Request.Session.Timout;
ViewData["SessionWillExpireOn"] = DateTime.Now.AddMinutes(Request.Session.Timeout);
return View(info);
}
}
이것은 :
<span>Your session will expire: <%= ViewData["SessionWillExpireOn"].ToString() %></span>
<span id="countDown" style="display:none></span>
<script type="text/javascript">
var sessionTimout = <%= ViewData["SessionTimeout"].ToString(); %>;
var approximateStart = new Date();
var notifyAfter = new Date(approximateStart + (sessionTimout - 1)*60*1000);
function startCountDown() {
setTimout(function() {
var now = new Date();
document.getElementById('countDown').style.display = 'inline';
document.getElementById('countDown').innerHTML = "Countdown: " + now.getMinutes();
if (now >= notifyAfter)
alert('About to expire...');
}, 5000);
}
document.onload=startCountDown;
</script>
그렇게 구문을 확인하시기 바랍니다 메모장에서보기를 썼다. 나는 또한 JS에서 DateTime을 정확하게 기억하지 않는다.
어쨌든 당신은 아이디어를보아야합니다.
탭이 열린 채로 있지만 다른 탭이 세션을 활성 상태로 유지하면 어떻게됩니까? 이 솔루션은 세션이 아직 살아 있는지 알기 위해 서버를 폴링하지 않습니다. –
@PederRice : 서버를 폴링 할 방법이 없습니다. 세션 시간 초과는 * sliding *이므로 서버에 요청하면 세션 시간 초과가 재설정됩니다. 기본적으로 시간 제한이 30 분이면 모든 설문 조사의 결과는 30 분이됩니다. –