LoginAuthorizationFilter.cs
using Microsoft.AspNetCore.Mvc.Filters; using PT.Common; using PT.Model; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace PT.Web.Mvc.App_Start { /// <summary> /// 登录授权过滤 /// </summary> public class LoginAuthorizationFilter : Attribute, IAuthorizationFilter { private SessionHelper sessionHelper; /// <summary> /// 登录授权过滤 /// </summary> /// <param name="context"></param> public void OnAuthorization(AuthorizationFilterContext context) { sessionHelper = new SessionHelper(context.HttpContext.Session); UserList user = sessionHelper.GetUserInfoString(); if (user == null) { context.HttpContext.Response.Redirect("/Login/Index"); } } } }