當我的會話將要在.net Mvc中清除時,我必須顯示一個彈出窗口。檢測會話超時並顯示當會話即將在mvc中清除時彈出
例如:enter link description here
我想同樣的事情在Mvc..what實現我應該怎麼辦???
這裏我有嘗試一些代碼:
這是控制器頁面(錯誤出現的是ClientScript不列入存在):
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000 * 60;
ClientScript.RegisterClientScriptBlock(this.GetType(),"SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
這裏是我的看法腳本(我是從控制器調用):
<script type="text/javascript">
function SessionExpireAlert(timeout) {
var seconds = timeout/1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function() {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
setTimeout(function() {
//Show Popup before 20 seconds of timeout.
$find("mpeTimeout").show();
}, timeout - 20 * 1000);
setTimeout(function() {
window.location = "Expired.aspx";
}, timeout);
};
function ResetSession() {
//Redirect to refresh Session.
window.location = window.location.href;
}
</script>
恐怕你不能這樣做。頁面對象可以在Web窗體中調用,因爲服務器端代碼是緊密耦合的,但是你不能使用mvc –
來做到這一點爲什麼???如何在mvc中執行..i認爲必須有任何方式來做到這一點..如果您有任何解決方案告訴我.. –
您可以使用JQuery JavaScript庫並觸發ajax請求,並在成功處理程序中執行您所需的操作。 –