mvc不登录的情况下无法跳转至其他页面--解决方法之一
在每个控制器里,加以下方法
/// <summary> /// 在调用视图之前拦截非法用户 /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { if (Session["userid"] == null) //判断session是否为空 { filterContext.Result = new RedirectResult(Url.Action("LoginShow", "Login"));//方法名,控制器名 return; } base.OnActionExecuting(filterContext); }