I have an simple MVC app I want to check first the session as this action
public ActionResult Index()
{
if (Session["UserInfo"] == null)
{
return RedirectToAction("Login", "Users");
}
return View();
}
My question is about is there a way to enforce this check to all actions without do it manual for each action?
you can use
OnActionExecutingand can also override this method to write custom logic so create a classadd namespaces in the class
and in your controller add
[SessionCheck]attribute like thisthis will check session on all the actions of controller or you can also add this attribute on action like this