如何授权的控制器集而不将注释上的每一个? [英] How to authorize a set of controllers without placing the annotation on each one?

查看:185
本文介绍了如何授权的控制器集而不将注释上的每一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有台控制器,这是每一个用于每个授权的类型。例如,A级授权将有一个集中每个需要A级授权控制器。有没有一种方法来将一个 [授权(角色=A类)] 属性的地方将适用于每一个这些控制器,而无需使用相同的装饰每个控制器属性?

I have sets of controllers which are each used for each authorization type. For example, a class A authorization will have a set of controllers each which require class A authorization. Is there a way to place one [Authorize(Role="Class A")] attribute somewhere which will apply to each of those controllers without having to decorate each controller with the same attribute?

推荐答案

您可以初始化从基本控制器衍生的控制器。即把你的属性上的控制器基类,以确保每个控制器内从基类派生的。

You can initialize those controllers derived from your base controller. namely put your attribute on a controller base class and to ensure that each controller within derived from base class.

[Authorize(Role="Class A")]
public class CustomBaseController : Controller{}

public class AController: CustomBaseController{}

public class BController: CustomBaseController{}

这篇关于如何授权的控制器集而不将注释上的每一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆