OWIN Middleware & CallContext

好久不见. 提交于 2019-12-10 19:12:24

问题


I have a few middlewares before the OAuth Middleware and a few after it.

app.Use<Middleware1>
app.Use<Middleware2>
app.UseOAuthBearerTokens(OAuthOptions)
app.Use<Middleware3>
app.Use<Middleware4>
app.Use<Middleware5>

If I set something in the CallContext in Middleware1 or in Middleware2, it isn't available in Middleware3 or 4 or in any of the API controllers; whereas, if I set something in the CallContext in Middleware3 or 4, it's available in all the succeeding middlewares and the API controllers.

I guess UseOAuthBearerTokens is resetting or creating a new CallContext?? Has anyone encountered this?

I can get away from it by taking one of these approaches: 1. Use OwinContext instead of CallContext. Drawback - need to reference OWIN in all the projects that need the value set in the context. 2. In Middleware1, I can set the value in OwinContext, and in the middleware that follows the OAuth middleware, I can retrieve the value from OwinContext and reset it in CallContext

Let me know a proper solution for this.

来源:https://stackoverflow.com/questions/39148034/owin-middleware-callcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!