【问题标题】:keep session time out long as possible with asp.net 4.0 with c#使用 c# 的 asp.net 4.0 使会话超时尽可能长
【发布时间】:2014-07-14 08:33:25
【问题描述】:

我已经创建了一个 asp.net 4.0 crm 网站。我在会话处理方面遇到了一个大问题,它意外地过期了我是如何应用一种来自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;
        }
    }

}

这就是我打电话的方式:

<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>

但是那里的问题是一样的。意外会话结束。

这是我的 web.config 行:

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

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

请帮帮我...

【问题讨论】:

    标签: c# asp.net session asp.net-4.0


    【解决方案1】:

    试试这个(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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 2016-04-02
      • 2014-05-16
      • 2011-01-17
      • 1970-01-01
      • 2015-09-08
      • 2012-01-02
      • 2011-09-13
      相关资源
      最近更新 更多