2013-09-05 1 views
0
  • MVC 4 웹 응용 프로그램이 있습니다.
    • iis7 환경에 배포되었습니다.
    • Windows 인증 및 가장을 사용합니다.
    • 회사 정책에 따라 15 분 후에 세션 제한 시간으로 설정됩니다.

이 항상 asp.net 응용 프로그램에서 잘 작동. 하지만 이제는 MVC4 응용 프로그램을 가지고 있으므로 global.asax와 session_start를 사용하여 세션 시간이 초과되었는지 다시 결정하는지 확인하는 대신 세션 만료 작업 필터를 설정했습니다.유휴 시간 초과 후 MVC4 응용 프로그램의 세션 시간 초과 처리기에서 무한 루프 문제가 발생합니다.

사용자가 응용 프로그램을 유휴 상태로 둘 때까지 모두 세션 시간 초과가 예상대로 작동합니다. 응용 프로그램 풀의 유휴 시간 제한은 20 분입니다.

내 사용자가 자신의 응용 프로그램을 열어두고 자주하는 회의에 참석하고 유휴 시간 제한에 도달 한 경우 다시 돌아와서 시도 할 때 응용 프로그램이 세션 시간 초과시 재 지정을 시도하면 오류 로그에서 루프에 갇히게되고 결코 재 지정되지 않습니다.

리디렉션을 시도하기에는 사실 (유휴 시간 초과)이 너무 늦습니까? 이전 asp.net 응용 프로그램 (비 MVC)에서 나는이 작업 (예 : 세션 시간 초과시 리디렉션)을 global.asax의 세션 시작에서 항상 수행하는 데 사용 했었습니다. obviosuly,이 이벤트는 항상 걷어 응용 프로그램 유휴 시간 초과하기 전에 맞았

어떤 도움을 주시면 감사하겠습니다

, 여기 내 세션 핸들러 내 코드입니다. 경우 사람에

public class SessionExpireAttribute : ActionFilterAttribute 
    { 
     /// <summary> 
     /// Called by the ASP.NET MVC framework after the action method executes. 
     /// </summary> 
     /// <param name="filterContext">The filter context.</param> 
     public override void OnActionExecuted(ActionExecutedContext filterContext) 
     { 
      base.OnActionExecuted(filterContext); 
     } 

     ///<summary> 
     ///Called by the ASP.NET MVC framework before the action method executes. 
     ///</summary> 
     ///<param name="filterContext">The filter context.</param> 
     public override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      if (filterContext.HttpContext.Session != null) 
      { 
       if (filterContext.HttpContext.Session.IsNewSession) 
       { 
        var sessionStateDetails =(SessionStateSection)ConfigurationManager.GetSection("system.web/sessionState"); 
        var sessionCookie = filterContext.HttpContext.Request.Headers["Cookie"]; 
        if ((sessionCookie != null) && (sessionCookie.IndexOf(sessionStateDetails.CookieName) >= 0)) 
        { 
         if (filterContext.HttpContext.Request.IsAjaxRequest()) 
         { 
          filterContext.HttpContext.Response.Clear(); 
          filterContext.HttpContext.Response.StatusCode = 403; 

         } 
         else 
         { 

          RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary(); 
          redirectTargetDictionary.Add("action", "SessionTimeout"); 
          redirectTargetDictionary.Add("controller", "Home"); 

          filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary); 

         } 
+0

MVC에서도 Session_Start를 사용할 수 있습니다. 왜 그런가요? –

+0

예 session_start는 MVC4에서 여전히 작동하고 올바르게 리디렉션됩니다. 그러나 블로그에서 읽은 적이 있는데, 나는 처리기를 사용하는 것이 더 나은 방법이라고 생각 했습니까? 이견있는 사람 ? 그리고 이것이 제가이 길로 내려간 이유입니다. – Alicia

답변

0

비슷한 문제가 발생한다 , 결국 에서 찾을 수있는 philpalmieri's jquery plugin을 사용하여이 문제를 해결했습니다. 앱이 유휴 상태로 전환하기 전에 내 inifinte 루프가 결코 발생하지 않도록 20 분 유휴 시간 초과로 설정하고,이 방법으로 그것을 호출하여

, 항상 세션 제한 시간에 다시 지시 :

function logout() { 
    ////session redirect goes here 
    var pathArray = window.location.pathname.split('/'); 
    var segment_1 = pathArray[1]; 
    window.location = window.location.protocol + "//" + window.location.host + "/" + segment_1 + "/Home/SessionTimeout"; 
} 

$(document).ready(function() { 
    var SEC = 1000; 
    var MIN = 60 * SEC; 
     $(document).idleTimeout({ 
      inactivity: 20 * MIN, 
      noconfirm: 2 * SEC, 
      redirect_url: 'javascript:logout()', 
      click_reset: true, 
      alive_url: '', 
      logout_url: '' 
     }); 
}); 

누구나 더 좋은 해결책이 있다면, 듣고 싶습니다 ...