How to transfer some data via signalR header or query string in .net core 2.0 application

Using signalR in .net 4.7, we were able to pass two variables from the client application to the signalR server. Here is the code snippet:

public class MyHub : Hub
{
    protected (string myVar1, string myVar2) GetValues() =>
            (
            Context.QueryString["MyVariable1"] ?? string.Empty,
            Context.QueryString["MyVariable2"] ?? string.Empty,
            );
}

The javascript client set the following variables as follows:

$.connection.hub.qs = {'MyVariable1' : 'val1', 'MyVariable2' : 'val2'};

Now we are trying to upgrade to the alpha version of signalR for .net core 2.0 applications. The blocker is that we can no longer use this method to get the values ​​myVar1 and myVar2. Not only QueryString is not available, but also headers. What is the best way to overcome this situation in order to transfer variables from the client application (Typescript) or even .net of the main application to the signalR server? Also - how do you set the variables on the client side?

+4
1

HttpContext :

var httpContext = Context.Connection.GetHttpContext();

httpContext.Request.Query["MyVariable"]

ASPNetCore 2.1

GetHttpContext() GetHttpContext() Context

using Microsoft.AspNetCore.Http.Connections;
....
var httpContext = Context.GetHttpContext();
+10

Source: https://habr.com/ru/post/1685887/


All Articles