How to check the Session Timeout
void Session_Start(object sender, EventArgs e)
{
if (Session.IsNewSession && Session["SessionExpire"] == null)
{
//Your code
}
}
You have many options to do this. But I will not recommend to use Global.asax
place to do such comparisons
Option - 1
This is also very important approach. You can use HttpModule
.
Option - 2
Base Controller class
Option - 3
You can apply the Action Filter to an entire Controller class like below
namespace MvcApplication1.Controllers
{
[MyActionFilter]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
}
}
Whenever any of the actions exposed by the Home controller are invoked – either the Index() method or the About() method, the Action Filter class will execute first.
namespace MvcApplication1.ActionFilters
{
public class MyActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//Your code for comparison
}
}
}
If you pay attention to the above code, the OnActionExecuting will execute before executing the Action Method
Option - 4
Using this approach will execute the OnActionExecuting
for Index method only.
namespace MvcApplication1.Controllers
{
public class DataController : Controller
{
[MyActionFilter]
public string Index()
{
//Your code for comparison
}
}
}
How to get the current request DataTokens
RouteData.Values["controller"] //to get the current Controller Name
RouteData.Values["action"] //to get the current action Name