操作过滤器异常
我想对除一个操作之外的每个操作应用操作过滤器。我该如何去做呢?
例如,假设我想将授权过滤器应用于除允许用户登录的操作之外的每个操作。
提前致谢.....
I want to apply an action filter to every action except one. How would I go for it?
For example, suppose I want to apply an authorization filter to every action except the action that lets the user login.
Thanks in advance.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 asp.net mvc 3 开始,您现在可以通过实施
IFilterProvider
接口。您可以在 Phil Haack 的博客。As of asp.net mvc 3 you can now apply conditional filters by implementing the
IFilterProvider
interface. You can find a good example almost exactly what you want on Phil Haack's blog.我将在 Global.asax 文件中全局应用操作过滤器,但我将设计过滤器以接受参数以停用它。我将在不需要的操作上应用过滤器,并为其提供停用参数。
I would apply the action filter globally in the Global.asax file but I'll design the filter to accept a parameter to deactivate it. I'll apply the filter on the action where I don't want it and give it the deactivation parameter.