ASP.NET MVC Session 过期验证跳转至登入页面
一、在要检查登入的控制器上继承 CheckLoginController 类
2、 CheckLoginController 类的写法
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace TaskManagement.Controllers { public class CheckLoginController : Controller { /// <summary> /// 实现统一登录验证检查 /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { //如果没有设置Session值那么就跳转到登入页面 //实现登录检查 if (Session["userinfo"] == null) { //RedirectResult tourl = new RedirectResult("/Login/UserLogin"); //filterContext.Result = tourl; ContentResult Cr = new ContentResult { Content = string.Format("<script type='text/javascript'>top.location.href='{0}';</script>", "/Login/UserLogin") }; filterContext.Result = Cr; } } } }