Is it possible to pass data from DelegatingHandler

2019-06-23 23:21发布

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?

1条回答
叛逆
2楼-- · 2019-06-24 00:07

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.

查看更多
登录 后发表回答