/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/SignalR/server/StackExchangeRedis/test/Startup.cs
54 строки
2 KB
Brennan
Fix preserving messages for stateful reconnect with backplane (#60900)
08 апр 2025, 00:28
Не верифицирован
08 апр 2025, 00:28
8491a27
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests; public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddSignalR(options => { options.EnableDetailedErrors = true; }) .AddMessagePackProtocol() .AddStackExchangeRedis(options => { options.Configuration.EndPoints.Add(Environment.GetEnvironmentVariable("REDIS_CONNECTION")); }); services.AddSingleton<IUserIdProvider, UserNameIdProvider>(); } public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapHub<EchoHub>("/echo"); endpoints.MapHub<StatefulHub>("/stateful", o => o.AllowStatefulReconnects = true); }); } private class UserNameIdProvider : IUserIdProvider { public string GetUserId(HubConnectionContext connection) { // This is an AWFUL way to authenticate users! We're just using it for test purposes. var userNameHeader = connection.GetHttpContext().Request.Headers["UserName"]; if (!StringValues.IsNullOrEmpty(userNameHeader)) { return userNameHeader; } return null; } } }