をお試しくださいこれにはPageMethod
を使用してください。
[WebMethod]
public static bool HasSessionTimedOut()
{
HttpSessionState session = HttpContext.Current.Session;
// I put this value into Session at the beginning.
DateTime? sessionStart = session[SessionKeys.SessionStart] as DateTime?;
bool isTimeout = false;
if (!sessionStart.HasValue)
{
isTimeout = true;
}
else
{
TimeSpan elapsed = DateTime.Now - sessionStart.Value;
isTimeout = elapsed.TotalMinutes > session.Timeout;
}
return isTimeout;
}
そして、これは私のJavascriptのである:ここで私はhereを発見したいくつかのコードです
<script type="text/javascript">
$(function() {
var callback = function(isTimeout) {
if (isTimeout) {
// Show your pop-up here...
}
};
setInterval(
function() {
// Don't forget to set EnablePageMethods="true" on your ScriptManager.
PageMethods.HasSessionTimedOut(false, callback);
},
30000
);
});
</script>