コード例 #1
0
        /// <summary>
        /// Maps incoming requests with the specified path to the specified <see cref="Hub"/> type.
        /// </summary>
        /// <typeparam name="THub">The <see cref="Hub"/> type to map requests to.</typeparam>
        /// <param name="path">The request path.</param>
        /// <param name="configureOptions">A callback to configure dispatcher options.</param>
        public void MapHub <THub>(PathString path, Action <HttpConnectionDispatcherOptions> configureOptions) where THub : Hub
        {
            // This will be null if someone is manually using the HubRouteBuilder(ConnectionsRouteBuilder routes) constructor
            // SignalR itself will only use the IEndpointRouteBuilder overload
            if (_endpoints != null)
            {
                _endpoints.MapHub <THub>(path, configureOptions);
                return;
            }

            // find auth attributes
            var authorizeAttributes = typeof(THub).GetCustomAttributes <AuthorizeAttribute>(inherit: true);
            var options             = new HttpConnectionDispatcherOptions();

            foreach (var attribute in authorizeAttributes)
            {
                options.AuthorizationData.Add(attribute);
            }
            configureOptions?.Invoke(options);

            _routes.MapConnections(path, options, builder =>
            {
                builder.UseHub <THub>();
            });
        }
コード例 #2
0
        public void MapHub <THub>(PathString path, Action <HttpConnectionOptions> configureOptions) where THub : Hub
        {
            // find auth attributes
            var authorizeAttributes = typeof(THub).GetCustomAttributes <AuthorizeAttribute>(inherit: true);
            var options             = new HttpConnectionOptions();

            foreach (var attribute in authorizeAttributes)
            {
                options.AuthorizationData.Add(attribute);
            }
            configureOptions?.Invoke(options);

            _routes.MapConnections(path, options, builder =>
            {
                builder.UseHub <THub>();
            });
        }