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.
A SignalR connection can end in any of the following ways: If the client calls the Stop method, a stop message is sent to the server, and both client and server end the SignalR connection immediately.
SignalR is deprecated. May I know the latest package for the same. - Microsoft Q&A.
In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).
SignalR requires that all HTTP requests for a specific connection be handled by the same server process. When SignalR is running on a server farm (multiple servers), "sticky sessions" must be used. "Sticky sessions" are also called session affinity by some load balancers.
There is a workaround, change AllowAnyOrigin
to SetIsOriginAllowed
:
app.UseCors(builder => builder
.AllowAnyHeader()
.AllowAnyMethod()
.SetIsOriginAllowed(_ => true)
.AllowCredentials()
);
I have found a solution. You can try the following code part:
.SetIsOriginAllowed (_ => true)
This worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With