【发布时间】:2016-06-30 20:40:18
【问题描述】:
我正在尝试将我的标准 WebApi 应用程序移至 OWIN,但在身份和 $batch 请求方面存在问题。
我目前有一个DelegatingHandler 可以检测并分配SendAsync 中的身份:
// Detect bearer token and build the identity above.
IOwinContext owinContext = request.GetOwinContext();
owinContext.Authentication.User = new ClaimsPrincipal(identity);
对于正常请求,这将继续到ODataController.User。但是在 $batch 请求时,该属性将返回到未经身份验证的 ClaimsIdentity。
即使GetOwinContext 返回一个IOwinContext 没有任何用户。我假设它为每个批次部分创建了一个新上下文,但我看不到任何找到原始上下文的方法。
任何帮助都会很棒!
【问题讨论】:
-
您是否在任何地方使用
.ConfigureAwait(false)并从调用者发出await'? This would cause the http context not to be reused when execution resumes. Also it would be interesting to see what is actually sent to the server (like http headers) when abatch` 请求,可能故障在于客户端实现(如果未发送不记名令牌)而不是在服务器。您是否可以就此代码或相关代码提供任何其他见解? -
不,我没有在任何地方使用
.ConfigureAwait(false)。
标签: asp.net-web-api odata owin owin-middleware