C# 使用asp.NET4.0和c尽可能长的保持会话超时#

C# 使用asp.NET4.0和c尽可能长的保持会话超时#,c#,asp.net,session,asp.net-4.0,C#,Asp.net,Session,Asp.net 4.0,我制作了一个asp.NET4.0CRM网站。我在会话处理方面有一个大问题,它是expires session(会话过期),出乎意料的是,我应用了keepalive.ashx中的一种技术,使会话尽可能长时间保持活动状态 <%@ WebHandler Language="C#" Class="keepalive" %> using System; using System.Web; using System.Web.SessionState; public class keepali

我制作了一个asp.NET4.0CRM网站。我在会话处理方面有一个大问题,它是expires session(会话过期),出乎意料的是,我应用了
keepalive.ashx
中的一种技术,使会话尽可能长时间保持活动状态

<%@ WebHandler Language="C#" Class="keepalive" %>

using System;
using System.Web;
using System.Web.SessionState;

public class keepalive : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        if (context.User.Identity.IsAuthenticated)
        {
            // authenticated sessions
            context.Response.ContentType = "text/plain";
            context.Response.Write("Auth:" + context.Session.SessionID);
        }
        else
        {
            // guest
            context.Response.ContentType = "text/plain";
            context.Response.Write("NoAuth:" + context.Session.SessionID);
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}

使用制度;
使用System.Web;
使用System.Web.SessionState;
公共类保持活动:IHttpHandler,iRequiresessionState
{
公共void ProcessRequest(HttpContext上下文)
{
if(context.User.Identity.IsAuthenticated)
{
//认证会话
context.Response.ContentType=“text/plain”;
Write(“Auth:+context.Session.SessionID”);
}
其他的
{
//客人
context.Response.ContentType=“text/plain”;
Write(“NoAuth:+context.Session.SessionID”);
}
}
公共布尔可重用{
得到{
返回false;
}
}
}
我是这样称呼的:

<script type="text/javascript">
        var interval = null;
        (function () {
            // keep me alive
            interval = setInterval(function () {
                $.get('../keepalive.ashx', function (d) {
                    $('#response').append(d + '<br/>');
                });
            }, 30000);
        })();


        // If we want to stop the interval....
        function Stop() {
            clearInterval(interval);
        }
</script>

var区间=null;
(功能(){
//让我活着
间隔=设置间隔(函数(){
$.get('../keepalive.ashx',函数(d){
$(“#响应”).append(d+”
); }); }, 30000); })(); //如果我们想停止间歇。。。。 函数停止(){ 间隔时间; }
但问题也一样。意外地,会议结束了

这是我的web.config行:

<sessionState mode="InProc" cookieless="false" timeout="525600"/>

但没有给出满意的解决方案

请帮助我…

试试这个(KeepSessionAlive.ashx可以为空):

function KeepSessionAlive() 
{
    $.get(ResolveUrl('~/KeepSessionAlive.ashx'), function (data) { });
}

$(function () {
    setInterval(KeepSessionAlive, 300000); //5 minutes
});


function ResolveUrl(url)
{
    if (url.indexOf("~/") == 0) 
    {
        url = baseUrl + url.substring(2);
    }
    return url;
}