开发者

Require [Authorize] for all actions in Asp.Mvc2

开发者 https://www.devze.com 2023-01-05 01:38 出处:网络
Is there a elegant way to require a开发者_C百科ll actions to require [Authorize] without having to use an AOP framework or similar? It seems to easy too forget to put the attribute on all controllers.

Is there a elegant way to require a开发者_C百科ll actions to require [Authorize] without having to use an AOP framework or similar? It seems to easy too forget to put the attribute on all controllers. I guess creating a base controller also can solve this, but again.. It's possible to forget to inherit from this one.


Putting it on the base controller is the easiest thing to do. To enforce compliance, you could write a unit test which enumerates over all the Controller types in your application and does a check to make sure that they subclass your CustomControllerBase.

0

精彩评论

暂无评论...
验证码 换一张
取 消