I often see such solutions your example : http://www.c-sharpcorner.com/UploadFile/91c28d/handle-session-expire-using-custom-attribute-in-Asp-Net-mvc/
Before you can Create BaseController.cs Controller and define OnActionExecuting Method.
public class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (Session["UserLogin"] == null)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "ManageAccount" }, { "action", "Login" } });
}
}
}
In the next step Create HomeController.cs inherited BaseController.cs file.
public class HomeController : BaseController
{
// GET: Home
public ActionResult Index()
{
return View();
}
}
BaseController OnActionExecuting method handled every request and check session control.
[HttpPost]
public ActionResult LoggedIn()
{
Session["UserLogin"] = true;
return RedirectToAction("Index", "Home");
}
Create example login post method, send request set UserLogin session parameter and redirect to Home/Index page.. Each controller that you inherit calls will perform session control for each request.
I Hope it helps.