来自Hub的HttpContext.GetOwinContext()的等价物是什么? [英] What is the equivalent of HttpContext.GetOwinContext() from a Hub?

查看:479
本文介绍了来自Hub的HttpContext.GetOwinContext()的等价物是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制台应用程序中自行托管了一个OWIN SignalR服务器。

I made a OWIN SignalR server self-hosted in a console app.

来自ASP.NET MVC应用程序中托管SignalR的示例(在IIS中) ),我看到这行代码:

From an example that is hosting SignalR in a ASP.NET MVC application instead (in IIS), I see this line of code:

var authenticateResult = await HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");

我无法访问 HttpContext in我的控制台应用程序(如果可能的话,不想引用System.Web.Mvc程序集)。在我的SignalR集线器类中, HttpContext.GetOwinContext()相当于什么?

I do not have access to HttpContext in my console app (and do not want to reference the System.Web.Mvc assembly if possible). What would be the equivalent of HttpContext.GetOwinContext() in my SignalR hub class?

推荐答案

Nuget包:

https ://www.nuget.org/packages/OwinRequestScopeContext/

在配置中:

app.UseRequestScopeContext();

在集线器中:

new Microsoft.Owin.OwinContext(OwinRequestScopeContext.Current.Environment)

这篇关于来自Hub的HttpContext.GetOwinContext()的等价物是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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