如果直接浏览器输入页面地址,因为session里没有用户就跳转到登陆页面
后台.cs代码:
public class LoginCheckFilterAttribute:ActionFilterAttribute
{
public bool IsCheck { get; set; }//是否登录标识,true:已经登录,false:未登录
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (IsCheck)
{
//校验用户是否已登录
if (filterContext.HttpContext.Session["loginUser"] ==null)
{
filterContext.HttpContext.Response.Redirect("/Home/Index");//未登录直接跳转到用户登录页面
}
}
}
}
标记到登录页面类上
[LoginCheckFilterAttribute(IsCheck = false)]