0

我正在尝试创建一条弹出消息,该消息将在用户的会话即将到期时警告用户(如果他们填写在线表格的时间过长)并在他们单击“确定”时将其扩展

这是我到目前为止所拥有的:

 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 中设置断点时,它永远不会被命中。所以我假设它永远不会到达那里。

4

1 回答 1

0

您的类将被编译为具有基本命名空间的程序集。如果您无法确定基本命名空间是什么,请尝试在 Visual Studio 的对象浏览器中查找 SessionHeartbeatHttpHandler 类。要显示对象浏览器,请将菜单导航到 View => Object Browser。或者,您可以使用键盘快捷键 CTRL+ALT+J 来调出它。

进入对象浏览器后,如有必要,您可以使用顶部的搜索栏来定位 SessionHeartbeatHttpHandler 类。单击类并观察右下窗格。它可能应该说以下内容:

Public Class SessionHeartbeatHttpHandler
     Member of MyBaseNamespace.SessionHeartbeatHttpHandler

复制“成员”之后的部分。这包含应该存在于您的 Web 配置文件中的正确值。

于 2013-04-15T19:43:22.470 回答