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:
- <system.web>
- <authentication mode="Forms">
- <forms loginUrl="~/Authentication/Login"></forms>
- </authentication>
- </system.web>
custom filtration class
- public override void OnActionExecuting(ActionExecutingContext filterContext)
- {
- if (HttpContext.Current.Session["UserInfo"] == null)
- {
- bool skipImportantTaskFilter = filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipImportantTaskAttribute), true) || filterContext.ActionDescriptor.IsDefined(typeof(SkipImportantTaskAttribute), true);
- if (skipImportantTaskFilter == false)
- {
- filterContext.Result = new RedirectResult("~/Login/Index");
- FormsAuthentication.SignOut();
- HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
- HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
- HttpContext.Current.Response.Cache.SetNoStore();
- HttpContext.Current.Session.Abandon();
- HttpContext.Current.Response.Write("<script language='javascript'>");
- HttpContext.Current.Response.Write("function ClearHistory()");
- HttpContext.Current.Response.Write("{");
- HttpContext.Current.Response.Write(" var backlen=history.length;");
- HttpContext.Current.Response.Write(" history.go(-backlen);");
- HttpContext.Current.Response.Write("}");
- HttpContext.Current.Response.Write("</script>");
- return;
- }
- }
- else
- {
- User user = (User)HttpContext.Current.Session["UserInfo"];
- if (user.ForcePwdChange && filterContext.ActionDescriptor.ActionName != "CallChangePassword" && filterContext.ActionDescriptor.ActionName != "ChangePassword")
- {
- filterContext.Result = new RedirectResult("~/Login/CallChangePassword");
- return;
- }
- }
- }