I am developing a user tracking solution using SignalR, as a fun project to learn SignalR for ASP.NET MVC applications.
Currently, I can track registered users and how long they have been on a particular page. If they go to another page, I also track this timer, which SignalR updates to reset ... Many other functions are implemented or partially implemented.
The problem I am facing is how to get the full Controller / Action / Parameters url inside the SignalR hub?
When I use HttpContext.Current.Request.Url , the url is always / signalr / connect .
NOTE:
var hub = $.connection.myHub; $.connection.hub.start();
located in _Layout.cshtml.
UPDATE:
I tried to use
var location = '@HttpContext.Current.Request.Url'; var hub = $.connection.myHub; $.connection.hub.start().done(function () { hub.setLocation(location); });
And the location is passed correctly, but I need it in the Connect () job no later than. Can this be done?
UPDATE 2:
This approach does not work
var hub = $.connection.myHub; $.connection.hub.start(function(){hub.setLocation(location)});
How Connect() called.
In my hub, I have several methods, but I would like to pass the value (in my case location) to Connect() , is this possible?
public class MyHub : Hub, IDisconnect, IConnected { public Task Connect() {
Update 3
Use a QueryString to pass data before Connect() appears.
var location = '@HttpContext.Current.Request.Url'; var hub = $.connection.myHub; $.connection.hub.qs = "location= + location; $.connection.hub.start();
Matija grcic
source share