1

ASP.Net Webアプリケーションでセッションタイムアウトの問題について助けが必要です。基本的に、セッションはログイン後約10〜15秒で失効します。MVC3 10秒後のセッションタイムアウト

側注:私は私のSession.IsNewSessionはログイン後3-4良いポストバック後にtrueに設定されます

カスタムをFormsAuthenticationのコンボや基本的なセキュリティを使用します。

私のWeb.Configには、次の...

私はタイムアウトは分を指し信じる
<sessionState mode="InProc" timeout="130" regenerateExpiredSessionId="true" stateNetworkTimeout="120" compressionEnabled="true" cookieless="UseCookies" /> 
<authentication mode="Forms"> 
    <forms timeout="120" ticketCompatibilityMode="Framework40" enableCrossAppRedirects="true" /> 
</authentication> 

を持っている....

私はのActionFilterとMVC 3アプリケーションが

を登録してい
public static void RegisterGlobalFilters(GlobalFilterCollection filters) 
    { 
     filters.Add(new MyActionFilterAttribute()); 
    } 

OnActionExecutingの内部では、権限のないユーザーがアクセスできないコントローラアクションへのアクセスを防止するために、現在のセッションをチェックします。

public override void OnActionExecuting(ActionExecutingContext filterContext) 
    {    
     HttpContext ctx = HttpContext.Current; 

     Player player = SessionHelper.GetCurrentPlayer(filterContext.HttpContext.Session); 

     if (player == null && ctx != null) 
     { 
      player = SessionHelper.GetCurrentPlayer(ctx.Session); 
     } 

     if (player == null || 
      (player.IsAdministrator == false && player.IsCoach == false && player.IsCommittee == false)) 
     { 
      if (filterContext.Controller is HomeController || filterContext.Controller is AccountController) 
      { 
       base.OnActionExecuting(filterContext); 
       return; 
      } 

      string ctxError = ctx != null ? "Context Exists" : "Context Doesnt Exist"; 
      string sessionError = filterContext.HttpContext.Session != null ? "filterContext.HttpContext.Session Exists" : "filterContext.HttpContext.Session Doesnt Exist"; 
      string requestSessionError = filterContext.RequestContext.HttpContext.Session != null ? "filterContext.RequestContext.HttpContext.Session Exists" : "filterContext.RequestContext.HttpContext.Session Doesnt Exist"; 

      throw new SecurityException(string.Format("Attempt to access {0} by user at {1} - {2} ({3}, {4}, {5})", 
                 filterContext.HttpContext.Request.RawUrl, 
                 filterContext.HttpContext.Request.UserHostAddress, 
                 filterContext.HttpContext.Session, 
                 ctxError, 
                 sessionError, 
                 requestSessionError)); 
     } 

     base.OnActionExecuting(filterContext); 
    } 
+0

セッションを使用して承認を確認する理由を教えてください。 – ZippyV

答えて

1

私は、Webサーバーがセッション寿命よりも速くAppPoolをリフレッシュしていると判断しました。これにより、同じSessionIdが使用されますが、IsNewSessionフラグも設定されます。

私はAppPoolの寿命を制御できないため、IISのInProcモードでセッションを維持することができました。

セッション状態の永続性をホストされたSqlServerデータベースに移動することで、AppPoolがリサイクルされているにもかかわらずセッションが維持されるという問題を解決しました。

管理者権限を持たないサーバーでホストされている場合は、安定したWebサイトがセッション状態を失っているのを見て、他の人にもこのソリューションをおすすめします。

ああ、私はIISログはここではかなり役に立たないことがわかりました。私が見つけた最良の診断ログは、これがシナリオであることを判断するための私自身の手動ログでした。