简体   繁体   English

通过ASP.NET MVC5中的动态验证访问控制器和方法

[英]Access controller and methods by dynamic validation in asp.net Mvc5

As everyone knows that we can access controller by role name in default security system of asp.net Mvc5 application. 众所周知,我们可以在asp.net Mvc5应用程序的默认安全系统中通过角色名称访问控制器。 But when we set role name on top of the controller for authorization , its hardcoded its not dynamic. 但是,当我们在控制器顶部设置角色名称以进行授权时,其硬编码不是动态的。 So i want to set authorization by controller name and also methods. 所以我想通过控制器名称以及方法来设置授权。 Thats why i have designed a table that have some column like : controller name , isEditable,isDeleteae,roleid Now i want to authorize on top of the controller by controller name. 这就是为什么我设计的表具有一些列,如:控制器名称,isEditable,isDeleteae,roleid现在我想通过控制器名称在控制器顶部进行授权。 Not using role name. 不使用角色名称。 Can anyone help me! 谁能帮我!

You can extend the AuthorizeAttribute to create your custom Authorization attribute which can be added into filter config. 您可以扩展AuthorizeAttribute以创建可以添加到过滤器配置中的自定义Authorization属性。 Override AuthorizeCore and HandleUnauthorizedRequest methods to customize your application requirement. 重写AuthorizeCore和HandleUnauthorizedRequest方法可自定义您的应用程序需求。

protected override bool AuthorizeCore(HttpContextBase httpContext)

 protected override void HandleUnauthorizedRequest(AuthorizationContext context)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM