Asp.Net MVC:在 AuthorizeAttribute 中使用模型绑定器?

发布于 2025-01-01 07:58:16 字数 219 浏览 1 评论 0原文

我有一个会话变量,它指示我所处的上下文。在此背景下将取决于一些授权。

目前,我有一个会话变量,并在自定义 AuthorizeAttribute 中检查它。效果很好。

但我发现了“ModelBinder”方式,它基本上在会话访问和控制器中使用之间添加了一层。

有没有办法在我的 AuthorizeAttribute 中也使用此 ModelBinder?

谢谢你!

I've a session vars that indicates me in which context I'm. On this contexts will depends some authorization.

Currently, I've a session vars, and I check it in a custom AuthorizeAttribute. It works great.

But I discovered the "ModelBinder" way, which basically adds a layer between between the access to the session and the use in controllers.

Is there a way to also use this ModelBinder in my AuthorizeAttribute?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2025-01-08 07:58:16

有没有办法在我的 AuthorizeAttribute 中也使用此 ModelBinder?

否,模型绑定器在授权属性 之后调用OnAuthorization 方法当然假设该方法已授权该请求。但如果您有兴趣检索请求参数,您可以使用 filtyerContext

var value = filterContext.Controller.ValueProvider.GetValue("someparam");

Is there a way to also use this ModelBinder in my AuthorizeAttribute?

No, the model binder is invoked after the authorize attribute OnAuthorization method assuming of course this method has authorized the request. But if you are interested in retrieving request parameters you could use the filtyerContext:

var value = filterContext.Controller.ValueProvider.GetValue("someparam");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文