Original: The context object in ASP. SignalR Hub
The context in the hub
When you use a hub, you'll find that comparing persistent connection classes with fewer events like onconnectioned, in fact there is. We need to go to override.
This seems to find out what the problem is, remember that there are connectionid and request parameters in the persistent connection class, and there is nothing here??? If there's a need to get connectionid.
In fact, there is no need to worry about it, because the context object has been encapsulated for us, as can be seen in the base class Hubbase, which is the Hubcallercontext type
F12 to see what's in this class, um ConnectionID, Headers, QueryString ... and so on.
// //Summary://represents the calling context of the client. Public classHubcallercontext {// //Summary://Initializes a new instance of the Microsoft.AspNet.SignalR.Hubs.HubCallerContext class. // //Parameters://Request://the current HTTP request. // //ConnectionID://The connection ID. PublicHubcallercontext (Irequest request,stringConnectionID); protectedHubcallercontext (); // //Summary://Gets the connection ID of the calling client. // //return Result://the connection ID of the calling client. Public Virtual stringConnectionID {Get; } // //Summary://gets the header of the request. // //return Result://the header of the request. Public VirtualInamevaluecollection Headers {Get; } // //Summary://gets the query string for the request. // //return Result://the query string for the request. Public VirtualInamevaluecollection QueryString {Get; } // //Summary://gets the Microsoft.AspNet.SignalR.IRequest for the current HTTP request. // //return Result://the Microsoft.AspNet.SignalR.IRequest of the current HTTP request. Public VirtualIrequest Request {Get; } // //Summary://gets the requested Cookie. // //return Result://the requested Cookie. Public Virtualidictionary<string, cookie> requestcookies {Get; } // //Summary://gets the System.Security.Principal.IPrincipal of the request. // //return Result://the requested System.Security.Principal.IPrincipal. Public VirtualIPrincipal User {Get; } }
ASP. SignalR the context object in the hub