How to check session timeout
void Session_Start(object sender, EventArgs e) { if (Session.IsNewSession && Session["SessionExpire"] == null) {
You have many options for this. But I will not recommend using Global.asax place for such comparisons.
Option 1
This is also a very important approach. You can use the HttpModule .
Option - 2
Base Controller class
Option - 3
You can apply an action filter to the entire controller class as shown below
namespace MvcApplication1.Controllers { [MyActionFilter] public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult About() { return View(); } } }
Whenever you invoke an action opened by the Home controller, either the Index () method or the About () method, the Action Filter class is first run.
namespace MvcApplication1.ActionFilters { public class MyActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) {
If you pay attention to the above code, OnActionExecuting will execute before executing the action method
Option - 4
With this approach, only the OnActionExecuting index-only method will be executed.
namespace MvcApplication1.Controllers { public class DataController : Controller { [MyActionFilter] public string Index() {
How to get the current DataTokens request
RouteData.Values["controller"]
source share