当会话状态超时在asp.net mvc中完成时,如何重定向到登录页面
发布时间:2020-12-16 00:42:14 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET MVC4应用程序,我正在实现的sessionTimeout像: configuration system.web sessionState timeout="2"/sessionState /system.web/configuration 并在验证中: configuration system.web authentication mode="Forms" forms loginUrl="~/Accou
我有一个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> 会话已过期(2分钟)后,我需要重定向到登录页面,但重定向不会发生。 如何更改代码以便重定向? 解决方法
一种方法就是这样
在会话过期的情况下,在每个操作中,您必须检查其会话,如果它为空,则重定向到登录页面。 但这是非常忙碌的方法 这是覆盖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(); } 这会让你工作。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 元素’system.webServer’有无效的子元素’重写
- asp.net – LINQ to SQL – 你的DataContext在哪里住?
- asp.net-mvc-4 – 带有绝对路径的ASP.NET MVC Bundle
- asp.net-mvc – MultiSelect jqgrid MVC3的OnClickButton函
- asp.net – 如何在url搜索词中处理web.config
- Asp.Net Web API跨层传递用户
- asp.net – 哈希与加密密码
- asp.net-mvc-2 – 在ASP.NET MVC 2中自定义ValidationSumma
- 如何在ASP.Net WebControl的“Content”内部属性??中包含其
- asp.net-mvc – 有一种很好的方法来控制显示模板应该如何呈