如何在asp.net mvc中获得全局授权
我一直在四处寻找,但没有看到任何相关规范,也许我搜索了错误的关键字。但我在这里所以我应该问一些事情......:)
我熟悉授权属性,但我认为它只适用于操作。如果我希望整个应用程序在访问任何操作之前先获得授权,我该怎么办?
如果只是在每个操作中重复将[授权]标签放在上面,这将是非常痛苦的。
非常感谢
I have been looking around but i don't see any spec for this, maybe i search a wrong keyword. But i'm here so i should ask something.. :)
I'm familiar with Authorize Attribute, but I think it only apply to Actions. What should i do if i want my whole application to authorize first before getting access to any actions?
It will be very pain to just repeat in every action to put [Authorize] tag on top of them.
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AuthorizeAttribute
仅适用于操作并不完全正确。它也可以应用于包含操作的类。如果您的应用程序有一个基本控制器类型(如果您愿意,可以是抽象的),并且每个其他控制器都是该基本类型的子类型,那么您的整个应用程序现在需要授权,只需输入几个字符。您应该找到一种方法让
AuthorizeAttribute
为您服务;这是在 ASP.NET MVC 中进行身份验证的标准方法。It is not quite correct that
AuthorizeAttribute
applies only to actions. It can also be applied to classes containing actions. If you have a base controller type for your application (which can be abstract, if you like), and every other controller is a subtype of that base type, then your entire application now requires authorization, with just a few characters of typing.You should find a way to make
AuthorizeAttribute
work for you; this is the standard way of doing authentication in ASP.NET MVC.不,您可以像操作一样使用 AuthorizeAttribute 标记您的控制器。请查看此处 。
No, you can mark your controller with AuthorizeAttribute like an action. Check out here.