Session

Vouchcast Session handling is accomplished in two ways. Through the traditional .NET Session timeout, and our own custom session which is used for segmenting users' profile by location.

How to implement session timeout in an Asp.net MVC5 application -

For Session Timeout::

App_Start > FilterConfig.cs

namespace VCAS
{
 ...
        public class SessionTimeoutAttribute : ActionFilterAttribute
        {
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                HttpContext ctx = HttpContext.Current;
                if (HttpContext.Current.Session["u"] != null)
                {
                    /// this handles session when data is requested through Ajax json
                    if (filterContext.HttpContext.Request.IsAjaxRequest())
                    {
                        JsonResult result = new JsonResult { Data = "Session Timeout!" };
                        filterContext.Result = result;
                    }
                    else
                    {
                        /// If session is expired then redirected to logout page which further redirect to login page. 
                        filterContext.Result = new RedirectResult("~/Account/Logout");
                        return;
                    }
                }
            }
        }
}

Controllers > HomeController.cs

namespace VCAS.Controllers
{
    [SessionTimeout]
    [Authorize]
    public class HomeController : Controller
    {
        ...
    }    

}

Views > Shared > _Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="refresh" content="900">  <!-- content="900" REFRESH page every 15mins -->
</head>

Web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <system.web>
      <sessionState mode="InProc" timeout="60" />   <!-- set for 1hr (60mins) -->
  </system.web>
</configuration>  

For Custom Session::