What is the equivalent of HttpContext.GetOwinConte

2019-07-13 13:50发布

问题:

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

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");

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?

回答1:

Nuget package:

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

In Configuration:

app.UseRequestScopeContext();

In hub:

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