Skip to content

Commit eca2400

Browse files
authored
Update signalr-howto-scale-multi-instances.md
1 parent 98fd921 commit eca2400

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

articles/azure-signalr/signalr-howto-scale-multi-instances.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ private class CustomRouter : EndpointRouterDecorator
9797
{ public override ServiceEndpoint GetNegotiateEndpoint(HttpContext context, IEnumerable<ServiceEndpoint> endpoints)
9898
{
9999
// Sample code showing how to choose endpoints based on the incoming request endpoint query
100-
var endpointName = context.Request.Query["endpoint"];
101-
if (endpointName.Count == 0)
102-
{
103-
throw new BadHttpRequestException("Invalid request.", 400);
104-
}
105-
100+
var endpointName = context.Request.Query["endpoint"].FirstOrDefault() ?? "";
106101
// Select from the available endpoints, don't construct a new ServiceEndpoint object here
107102
return endpoints.FirstOrDefault(s => s.Name == endpointName && s.Online) // Get the endpoint with name matching the incoming request
108103
?? base.GetNegotiateEndpoint(context, endpoints); // Or fallback to the default behavior to randomly select one from primary endpoints, or fallback to secondary when no primary ones are online
@@ -182,15 +177,9 @@ private class CustomRouter : EndpointRouterDecorator
182177
{
183178
public override ServiceEndpoint GetNegotiateEndpoint(IOwinContext context, IEnumerable<ServiceEndpoint> endpoints)
184179
{
185-
// Override the negotiate behavior to get the endpoint from query string
186-
var endpointName = context.Request.Query["endpoint"];
187-
if (string.IsNullOrEmpty(endpointName))
188-
{
189-
context.Response.StatusCode = 400;
190-
context.Response.Write("Invalid request.");
191-
return null;
192-
}
193-
180+
// Sample code showing how to choose endpoints based on the incoming request endpoint query
181+
var endpointName = context.Request.Query["endpoint"] ?? "";
182+
// Select from the available endpoints, don't construct a new ServiceEndpoint object here
194183
return endpoints.FirstOrDefault(s => s.Name == endpointName && s.Online) // Get the endpoint with name matching the incoming request
195184
?? base.GetNegotiateEndpoint(context, endpoints); // Or fallback to the default behavior to randomly select one from primary endpoints, or fallback to secondary when no primary ones are online
196185
}

0 commit comments

Comments
 (0)