none
MVC 4 Detecting Session Timeout - CustomActionFilter RRS feed

  • Question

  • The following code       

    public override void OnActionExecuting(ActionExecutingContext filterContext)         {             if (filterContext.HttpContext.Session != null)             {                 if (filterContext.HttpContext.Session.IsNewSession)                 {                     string cookie = filterContext.HttpContext.Request.Headers["Cookie"];                     if ((cookie != null) && (cookie.IndexOf("_sessionId") >= 0))                     {                         filterContext.Result = newRedirectResult("~/SessionExpired/Index");                         return;                     }                 }             }             base.OnActionExecuting(filterContext);       }

    is standard for checking session expiration.

    However in my case the the line (cookie != null) && (cookie.IndexOf("_sessionId") >= 0)

    always returns null and thus the user is never redirected.

    I am testing with a brand new wizard created MVC 4 project.

    I can find a complete download sample to where my config my be wrong.

        <authentication mode="Forms">

        <forms loginUrl="~/Account/Login" timeout="1" slidingExpiration="true" name=".ASPXFORMSAUTH" />  

      </authentication>    

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

    Please advise why this code fails or provide a link with a complete download sample project. .Net 4.5 | VS 2012 | local IIS Web Server , IIS Express

       
    • Moved by Jason Dot Wang Wednesday, November 27, 2013 3:30 AM This thread is about ASP.NET
    Tuesday, November 26, 2013 10:57 PM

Answers

  • Hi gandalf123,

      Welcome to MSDN Forum Support.

      You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.

      Sincerely,

      Jason Wang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 27, 2013 3:30 AM
  • Hello,

    Specifically, this should be asked in the ASP.Net MVC forum on forums.asp.net.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Friday, May 2, 2014 7:54 PM
    Moderator

All replies

  • Hi gandalf123,

      Welcome to MSDN Forum Support.

      You are more likely to get more efficient responses to ASP.NET issues at http://forums.asp.net where you can contact ASP.NET experts.

      Sincerely,

      Jason Wang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 27, 2013 3:30 AM
  • Hello,

    Specifically, this should be asked in the ASP.Net MVC forum on forums.asp.net.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Friday, May 2, 2014 7:54 PM
    Moderator