我有一个ASP.NET MVC4应用程序,我正在实现的sessionTimeout像:
<configuration> <system.web> <sessionState timeout="2"></sessionState> </system.web> </configuration>
并在验证中:
<configuration> <system.web> <authentication mode="Forms"> <forms loginUrl="~/Account/logon" timeout="1" /> </authentication> </system.web> </configuration>
解决方法
一种方法就是这样
在会话过期的情况下,在每个操作中,您必须检查其会话,如果它为空,则重定向到登录页面。
在会话过期的情况下,在每个操作中,您必须检查其会话,如果它为空,则重定向到登录页面。
但这是非常忙碌的方法
为了完成这一切,您需要创建自己的ActionFilterattribute,这将执行此操作,您只需要在每个操作方法中添加此属性。
这是覆盖ActionFilterattribute的类。
public class SessionExpireFilterattribute : ActionFilterattribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; // check if session is supported CurrentCustomer objCurrentCustomer = new CurrentCustomer(); objCurrentCustomer = ((CurrentCustomer)SessionStore.GetSessionValue(SessionStore.Customer)); if (objCurrentCustomer == null) { // check if a new session id was generated filterContext.Result = new RedirectResult("~/Users/Login"); return; } base.OnActionExecuting(filterContext); } }
[SessionExpire] public ActionResult Index() { return Index(); }
这会让你工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。