-
-
Save ThomasPe/78bfef4aa6e0b2c4e5beef24178c0b78 to your computer and use it in GitHub Desktop.
SignalR Service Negotiation in C# ASP.NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<NegotiationResponse> Negotiate(Guid userId, CancellationToken ct) | |
{ | |
string connectionString = "Endpoint=https://myapp.service.signalr.net;AuthType=azure.msi;Version=1.0;" | |
ServiceManager serviceManager = new ServiceManagerBuilder() | |
.WithOptions(option => | |
{ | |
option.ServiceEndpoints = | |
[ | |
new(connectionString) | |
]; | |
}) | |
.BuildServiceManager(); | |
ServiceHubContext hubContext = await _serviceManager | |
.CreateHubContextAsync(_options.HubName, ct) | |
.ConfigureAwait(false); | |
NegotiationResponse response = await _hubContext.NegotiateAsync( | |
new NegotiationOptions() | |
{ | |
UserId = userId.ToString(), | |
EnableDetailedErrors = _options.EnableDetailedErrors | |
}, ct) | |
.ConfigureAwait(false); | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment