2014-07-14 2 views
0

asp.net 4.0 crm 웹 사이트를 만들려면 가능하면 세션 시간이 길어 지도록하십시오. 세션 처리에있어 큰 문제가 하나 있습니다. 예기치 않게 세션이 만료되었는데 가능한 한 오랫동안 세션을 유지하는 keepalive.ashx의 기술을 어떻게 적용 했습니까?asp.net 4.0 with C#

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

을하지만, 문제가 동일합니다

<%@ 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; 
     } 
    } 

} 

이 내가 전화하는 방법입니다. unexpectlly 세션 나가.

이 내 Web.config의 라인입니다 :

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

하지만 만족 솔루션을 제공 does't.

좀 도와주세요 ...

답변

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