从OWIN管道传递逻辑呼叫上下文的WebAPI控制器 [英] Passing logical call context from OWIN pipeline to WebApi controller

查看:274
本文介绍了从OWIN管道传递逻辑呼叫上下文的WebAPI控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过对逻辑调用上下文语境信息(使用 CallContext.LogicalSetData(CallContextKey,值))根据斯蒂芬·克利里的帖子<一个href=\"http://blog.stephencleary.com/2013/04/implicit-async-context-asynclocal.html\">http://blog.stephencleary.com/2013/04/implicit-async-context-asynclocal.html;并通过<一的code启发href=\"https://github.com/neuecc/OwinRequestScopeContext\">https://github.com/neuecc/OwinRequestScopeContext.

I'm trying to pass contextual information on the logical call context (using CallContext.LogicalSetData(CallContextKey, value)) as per Stephen Cleary's post http://blog.stephencleary.com/2013/04/implicit-async-context-asynclocal.html; and inspired by the code in https://github.com/neuecc/OwinRequestScopeContext.

的值将是可利用通过了OWIN管道,但它不提供在呼叫进入的WebAPI控制器,​​该值未设置。

The value will be available through out the OWIN pipeline, but it is not available when the call enters the WebApi controller, the value is not set.

我也注意到,在控制器中设置断点时,我看不到在调用堆栈中的OWIN管道。显然,ASP.NET是一个单独的呼叫上下文使得控制器电话。

I also noticed that when setting a breakpoint in the controller, I can't see the OWIN pipeline in the call stack. Apparently, ASP.NET is making controller calls on a separate call context.

因此​​,


  • 为什么(以及如何)确实ASP.NET隔离OWIN管道调用上下文到的WebAPI控制器?

  • Why (and how) does ASP.NET isolate the call context from OWIN pipeline to the WebApi controller?

如何从管道上下文数据传递给控制器​​?

How can I pass contextual data from Pipeline to the controller?

推荐答案

我花了几天的时间才能找出原因CallContext中在API控制器清楚,直到我读这篇文章:
<一href=\"http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline\" rel=\"nofollow\">http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline

It took me several days to find out why the CallContext is clear in the API controller, until I read this article: http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline

如果两个中间件在不同的IIS运行阶段,他们将有不同的CallContext中。

如果你正在主持OWIN在IIS上,并希望在所有中间件同样的要求范围内,那么,使用旧的 HttpContext.Current 代替。

If you are hosting OWIN on IIS and want the same request context in all middlewares, well, use the old HttpContext.Current instead.

这篇关于从OWIN管道传递逻辑呼叫上下文的WebAPI控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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