What is the proper way to access IUrlHelper
from my SignalR Hub
class (ASP.Net Core 2.1)?
I am trying to generate the links to different actions dynamically inside Hub class.
What is the proper way to access IUrlHelper
from my SignalR Hub
class (ASP.Net Core 2.1)?
I am trying to generate the links to different actions dynamically inside Hub class.
You cannot. UrlHelper
requires an ActionContext
instance to create URLs, which only exists within the context of a request. A SignalR hub exists outside of the request pipeline. Instead, you should pass the URL into the appropriate hub method from someplace where UrlHelper
does exist, like a controller action, instead of relying on the hub to generate it.