.net core 登入全域性驗證過濾器
最近公司再用.net core做專案。 碰到了登入驗證許可權這一塊。使用過濾器不需要每個方法上都去判斷登入是否失效。有的時候還會忘記對驗證
希望對大家有幫助
mvc core的寫法:
public class PermissionRequiredAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{var isDefined = false;
var controllerActionDescriptor = filterContext.ActionDescriptor as ControllerActionDescriptor;
if (controllerActionDescriptor != null)
{
isDefined = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true)
.Any(a => a.GetType().Equals(typeof(NoPermissionRequiredAttribute)));
}
if (isDefined) return;
if (MyHttpContext.Current.Session.GetString("LoginInfo") == null)
{
filterContext.Result = new RedirectResult("/Account/Login");
}
base.OnActionExecuting(filterContext);
}
}
//不需要登入
public class NoPermissionRequiredAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
}
}
//在不需要的方法上面打上標記
[NoPermissionRequired]
public ActionResult Login()
{
}
相關文章
- .Net MVC中定義全域性過濾器及在Action中排除全域性過濾器MVC過濾器
- asp.net mvc中的使用者登入驗證過濾器ASP.NETMVC過濾器
- .NetCore——全域性異常過濾器ExceptionFilterAttributeNetCore過濾器ExceptionFilter
- 在Asp.Net Core中使用ModelConvention實現全域性過濾器隔離ASP.NET過濾器
- ASP.NET Core 過濾器ASP.NET過濾器
- Vue定義全域性過濾器filterVue過濾器Filter
- asp.net core MVC 過濾器之ActionFilter過濾器(二)ASP.NETMVC過濾器Filter
- .net core中的哪些過濾器過濾器
- ASP.NET登入驗證ASP.NET
- 理解ASP.NET Core - 過濾器(Filters)ASP.NET過濾器Filter
- (精華)2020年7月21日 ASP.NET Core 模型驗證過濾器ASP.NET模型過濾器
- 使用路由閘道器的全域性過濾功能路由
- .net core中的哪些過濾器 (Authorization篇)過濾器
- 【ASP.NET Core】MVC過濾器:執行流程ASP.NETMVC過濾器
- 【ASP.NET Core】MVC過濾器:常見用法ASP.NETMVC過濾器
- Asp.net core 過濾器的簡單使用ASP.NET過濾器
- 【SSO】--單點登入之過濾器(filter)過濾器Filter
- .NET Core-全域性效能診斷工具
- vue2.0全域性路由守衛(全域性控制登入)Vue路由
- 通用的使用者登入過濾器(SessionFilter)過濾器SessionFilter
- ASP.NET MVC 5改進了基於過濾器的身份驗證ASP.NETMVC過濾器
- sql 注入越過登入驗證例項SQL
- ASP.NET Core 中簡單Session登入校驗ASP.NETSession
- spring boot 實現監聽器、過濾器、全域性異常處理Spring Boot過濾器
- [譯]ASP.NET Core 2.0 全域性配置項ASP.NET
- 通過selenium突破極驗驗證實現登入
- MySQL登入驗證方式MySql
- JS登入驗證nullJSNull
- python驗證登入Python
- NetCore過濾器NetCore過濾器
- 【asp.net core 系列】13 Identity 身份驗證入門ASP.NETIDE
- .NET Core如何全域性獲取使用者資訊?
- 實現elementUI表單的全域性驗證UI
- Asp.Net Core webapi+net6 使用資源篩選器(過濾器) 做快取ASP.NETWebAPI過濾器快取
- ASP.NET Core Authentication系列(二)實現認證、登入和登出ASP.NET
- 讓CNN跑得更快,騰訊優圖提出全域性和動態過濾器剪枝CNN過濾器
- Laravel- Auth 登入驗證Laravel
- GitHub--oauth驗證登入GithubOAuth