AuthorizeFilter.cs 912 B

12345678910111213141516171819202122232425
  1. using System;
  2. using Library;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. namespace MySystem
  5. {
  6. public class AuthorizeFilter : IAuthorizationFilter
  7. {
  8. /// <summary>
  9. /// 请求验证,当前验证部分不要抛出异常,ExceptionFilter不会处理
  10. /// </summary>
  11. /// <param name="context"></param>
  12. public void OnAuthorization(AuthorizationFilterContext context)
  13. {
  14.         //这里可以做复杂的权限控制操作
  15.         //if (context.HttpContext.User.Identity.Name != "1") //简单的做一个示范
  16.         //{
  17.         // //未通过验证则跳转到无权限提示页
  18.         // RedirectToActionResult content = new RedirectToActionResult("NoAuth", "Exception", null);
  19.         // context.Result = content;
  20.         //
  21. }
  22. }
  23. }