ibiza ibiza - 3 months ago 132
HTTP Question

What is the equivalent of HttpContext.GetOwinContext() from a Hub?

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?

Answer

Nuget package:

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

In Configuration:

app.UseRequestScopeContext();

In hub:

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