开发者

Require [Authorize] for all actions in Asp.Mvc2

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜