Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IOwinContext from SignalR hub?

How to access IOwinContext from SignalR hub (for instance from HubCallerContext)?

like image 533
TN. Avatar asked Oct 19 '25 03:10

TN.


1 Answers

If you're on IIS, you can access the IOwinContext for the current connected client via the HubCallerContext (Context property of the Hub base class):

using Microsoft.AspNet.SignalR;
using System.Web;

...

Context.Request.GetHttpContext().GetOwinContext()

GetHttpContext is an extension under Microsoft.AspNet.SignalR and GetOwinContext is an extension under System.Web, so make sure you import both of those namespaces and include the Microsoft.Owin.Host.SystemWeb assembly as a project reference.

like image 50
justisb Avatar answered Oct 21 '25 15:10

justisb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!