Karan Thakkar

Karan Thakkar

  • 1.4k
  • 204
  • 85.7k

How will I set time for session timeout in form authention?

Mar 26 2019 2:13 AM
I want to set session 1 minute in form authentication in asp.net MVC
 
below is my code I tried several ways but I failed to do so.
 
webconfig code:
  1. <system.web>  
  2. <authentication mode="Forms">  
  3. <forms loginUrl="~/Authentication/Login"></forms>  
  4. </authentication>  
  5. </system.web> 
custom filtration class
  1. public override void OnActionExecuting(ActionExecutingContext filterContext)  
  2. {  
  3. if (HttpContext.Current.Session["UserInfo"] == null)  
  4. {  
  5. bool skipImportantTaskFilter = filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipImportantTaskAttribute), true) || filterContext.ActionDescriptor.IsDefined(typeof(SkipImportantTaskAttribute), true);  
  6. if (skipImportantTaskFilter == false)  
  7. {  
  8. filterContext.Result = new RedirectResult("~/Login/Index");  
  9. FormsAuthentication.SignOut();  
  10. HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);  
  11. HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));  
  12. HttpContext.Current.Response.Cache.SetNoStore();  
  13. HttpContext.Current.Session.Abandon();  
  14. HttpContext.Current.Response.Write("<script language='javascript'>");  
  15. HttpContext.Current.Response.Write("function ClearHistory()");  
  16. HttpContext.Current.Response.Write("{");  
  17. HttpContext.Current.Response.Write(" var backlen=history.length;");  
  18. HttpContext.Current.Response.Write(" history.go(-backlen);");  
  19. HttpContext.Current.Response.Write("}");  
  20. HttpContext.Current.Response.Write("</script>");  
  21. return;  
  22. }  
  23. }  
  24. else  
  25. {  
  26. User user = (User)HttpContext.Current.Session["UserInfo"];  
  27. if (user.ForcePwdChange && filterContext.ActionDescriptor.ActionName != "CallChangePassword" && filterContext.ActionDescriptor.ActionName != "ChangePassword")  
  28. {  
  29. filterContext.Result = new RedirectResult("~/Login/CallChangePassword");  
  30. return;  
  31. }  
  32. }  
  33. }

Answers (1)