是否有可能从DelegatingHandler数据传递给控制器​​中的ASP.NET Web API? [英] Is it possible to pass data from DelegatingHandler to Controller in ASP.NET Web API?

查看:145
本文介绍了是否有可能从DelegatingHandler数据传递给控制器​​中的ASP.NET Web API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施授权相关DelegatingHandler哪里负载了API用户(主叫)配置文件从数据库中。当授权成功,我想通过这个实例的控制,否则我必须重新加载它。

I'm implementing an authorization related DelegatingHandler where I load-up the api user (caller) profile from database. When the authorization is successful I'd like to pass this instance to the controller otherwise I'd must load it again.

有没有办法做到这一点,而无需使用会话或依赖库缓存?

Is there any way to do this without using session or rely on repository cache?

推荐答案

该型Htt prequestMessage类包含字典属性,你可以用它来存储这些信息。不过,我不知道这是否是GET处理程序调用和控制行动之间依然存在。否则,你可以在那里已经创建的操作环境的行为过滤器试试。行动背景下,您可以访问操作的参数,在这里你可以添加额外的参数传递给动作。

The HttpRequestMessage class contains a dictionary "Properties" that you could use to store that information. However, I am not sure if it is get persisted between the handler invocation and the controller action. Otherwise, you can try with an action filter where the action context is already created. The action context gives you access to the action arguments, where you can add an additional argument to be passed to the action.

这篇关于是否有可能从DelegatingHandler数据传递给控制器​​中的ASP.NET Web API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆