I am using SignalR in my ASP.NET web application. Here I am calling client from outside to hub class using IHubContext
. I need to get the current user's connection ID in order to send messages to the current user only. How can I get the connection ID on the client side?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- Using :remote => true with hover event
- How to store image outside of the website's ro
- Is there a way to play audio on a mobile browser w
- 'System.Threading.ThreadAbortException' in
For a .NET Client it is on the
Connection
object, inherited byHubConnection
.So typically can be found on
Server : Context.ConnectionId => "dJSbEc73n6YjGIhj-SZz1Q"
Client :
=> wss://localhost:5001/notify?id=dJSbEc73n6YjGIhj-SZz1Q
you can extract the id. (far to be a perfect solution)
use the following code it works for me.
in the hub class.
in the hub class file create the following class
and outside the hub class.
This works for me:
Yep. You can use
$.connection.hub.id
.To get the full hub url, you can say:
hubConnection.connection.transport.webSocket.url
this is something like:
"wss://localhost:1234/myHub?id=abcdefg"
Regex to get the ID:
var r = /.*\=(.*)/ var id = r.exec(url)[1]