我正在尝试创建一条弹出消息,该消息将在用户的会话即将到期时警告用户(如果他们填写在线表格的时间过长)并在他们单击“确定”时将其扩展
这是我到目前为止所拥有的:
function ShowTimeoutWarning() {
if(window.confirm("You will be logged out due to inactivity in 5 minutes. If you are working on something, please save your work now to prevent data loss!")) {
extendSession();
}
}
function beginSessionTimer() {
// 3000ms = 3s
// 300000ms = 5 minutes
// 900000ms = 15 minutes
window.setTimeout('ShowTimeoutWarning();', 3000)
}
function extendSession() {
$.get(
"/SessionHandler.ashx",
null,
function (data) {
//start the countdown again
beginSessionTimer();
},
"json"
);}
会话处理程序.ashx
<%@ WebHandler Language="C#" Class="SessionHandler" %>
using System;
using System.Web;
using System.Web.SessionState;
public class SessionHandler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
context.Session["Heartbeat"] = DateTime.Now;
}
public bool IsReusable {
get {
return false;
}
}
}
在我的网络配置中,我有以下内容:
<httpHandlers>
<add verb="GET,HEAD" path="SessionHandler.ashx" validate="false" type="SessionHandler"/>
</httpHandlers>
我使用 FireFox 的 httpFox 查看标题,我看到的错误是:
> <b> Description: </b>An error occurred during the processing of a
> configuration file required to service this request. Please review the
> specific error details below and modify your configuration file
> appropriately.
> <br><br>
>
> <b> Parser Error Message: </b>Could not load type 'SessionHandler'.<br><br>
当我在 httpHandler 中设置断点时,它永远不会被命中。所以我假设它永远不会到达那里。