天道酬勤,学无止境

asp.net-core-signalr

How to authorize SignalR Core Hub method with JWT

I am using JWT authentication in my ASP.NET Core 2.0 application with OpenIddict. I am following idea in this thread and calling AuthorizeWithJWT method after SignalR handshake. But now, I do not know what should I set in AuthorizeWithJWT method so I can use [Authorize(Roles="Admin")] for example. I tried with setting context user, but it is readonly: public class BaseHub : Hub { public async Task AuthorizeWithJWT(string AccessToken) { //get user claims from AccesToken this.Context.User = user; //error User is read only } } And using authorize attribute: public class VarDesignImportHub

2021-05-09 03:36:31    分类:问答    authentication   signalr   openiddict   asp.net-core-signalr

How to buffer messages on signal hub and send them when the right client appears?

I hawe two type of clients connecting my signalR server (ASP.NET Core). Some of them are senders, and some of them are receivers. I need to route messages from senders to the receivers, which is not a problem, but when there is no receivers, I need to somehow buffer messages and not lose them (probably the best is ConcurrentQueue in some kind of a singleton class) but when the first receiver connect, the message buffer needs to start dequeue. Which is the best approach for this? I created singleton class that wraps arround ConcurrentQueue collection and I enqueue and dequeue messages there

2021-05-03 08:59:14    分类:问答    c#   asp.net-core   signalr   asp.net-core-signalr

SignalR Core 2.2 CORS AllowAnyOrigin() breaking change

To connect via SignalR to an ASP.NET Core 2.1 server from any origin, we had to configure the pipeline as follows: app.UseCors ( builder => builder .AllowAnyHeader () .AllowAnyMethod () .AllowAnyOrigin () .AllowCredentials () ) According to this document, ASP.NET Core 2.2 no longer allows the combination of AllowAnyOrigin and AllowCredentials, so what would be the solution? Whereas the SignalR Core always sends withCredentials:true in the XMLHtppRequest. What I need is that from any origin and without credentials, our users can connect to the SignalR Hub.

2021-05-01 03:28:51    分类:问答    c#   asp.net-core   asp.net-core-signalr   asp.net-core-2.2

Why is Azure SignalR Service recommended when deploying a Blazor Server Side app?

When I publish a Blazor Server Side app on Azure, Visual Studio prompts a message that says: Your application is making use of SignalR. For environments that need to scale we strongly recommend adding a dependency on Azure SignalR Service. However, my app works just fine as it is, without making use of Azure SignalR Service. So I was wondering if it really makes sense to integrate it or it's just a way for Microsoft to squeeze a few extra dollars from our pockets... Has anyone tried deploying a Blazor Server Side app with and without Azure SignalR Service, in order to test if there is any

2021-04-27 18:49:13    分类:问答    azure   blazor-server-side   asp.net-core-signalr   azure-signalr   asp.net-blazor

SignalR call client methods from outside the Hub class AspNetCore

I'm trying to call client methods outside the hub on SignalR, the link below shows how to do this in the old version, although i'm unsure how to do this in the SignalR ASP.NET Core version. I've found a reference to a old post and using a reference to Microsoft.AspNetCore.SignalR.Infrastructure.IConnectionManager although this namespace doesn't seem to existing anymore. An example would be great? Old version: How to call client methods and manage groups from outside the Hub class

2021-04-21 03:08:16    分类:问答    asp.net-core   signalr   asp.net-core-signalr

Connection ID when calling SignalR Core Hub method from Controller

This is a follow-up to another question and answer. What's the effect of calling HubContext.Clients.Caller or HubContext.Clients.Others from the controller? I see it depends on the connection ID. What value would it have in this situation? If the connection ID (and thus Caller and Others) is invalid then (from within the controller action) how could I obtain a connection ID (for the client currently calling the Web API) that I could use with HubContext.Clients's methods?

2021-04-20 15:44:35    分类:问答    c#   signalr   asp.net-core-signalr   asp.net-core-2.1

Get Hub Context in SignalR Core from within another object

I am using Microsoft.AspNetCore.SignalR (latest release) and would like to get the hub context from within another object that's not a Controller. In the "full" SignalR, I could use GlobalHost.ConnectionManager.GetHubContext<MyCoolHub>(); I have seen a lot of examples of just adding Microsoft.AspNetCore.SignalR.IHubContext<MyCoolHub> as a parameter to the Ctor of a Controller, but no examples (that work) for otherwise. ETA: So, this is what I have working. Is this hacky? public class MyHub : Hub public static IHubContext<MyHub> GlobalContext { get; private set; } public MyHub(IHubContext<MyHub

2021-04-10 05:40:23    分类:问答    c#   asp.net-core   asp.net-core-signalr

Call SignalR Core Hub method from Controller

How can I call SignalR Core Hub method from Controller? I am using ASP.NET Core 2.0 with Microsoft.AspNetCore.SignalR (1.0.0-alpha2-final). I have windows service which communicate with Excel, SolidEdge ... When operation is complete it post request to my controller in ASP.NET Core application. Now I need to inform all clients connected to server with SignalR that external program completed some task. I can not change the way window service works. (Can not connect to SignalR from window service). I found plenty solution for old SignalR (GlobalHost.ConnectionManager.GetHubContext), but much has

2021-03-22 15:28:21    分类:问答    c#   signalr   asp.net-core-2.0   asp.net-core-signalr