diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs index cdeeb89bb1..e9e3efeb4e 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Startup.cs @@ -77,10 +77,10 @@ namespace Microsoft.AspNetCore.SignalR.Test.Server } app.UseFileServer(); - app.UseSockets(options => options.MapEndPoint("echo")); - app.UseSignalR(options => options.MapHub("testhub")); - app.UseSignalR(options => options.MapHub("uncreatable")); - app.UseSignalR(options => options.MapHub("authorizedhub")); + app.UseSockets(options => options.MapEndPoint("/echo")); + app.UseSignalR(options => options.MapHub("/testhub")); + app.UseSignalR(options => options.MapHub("/uncreatable")); + app.UseSignalR(options => options.MapHub("/authorizedhub")); app.Use(next => async (context) => { diff --git a/samples/ChatSample/Startup.cs b/samples/ChatSample/Startup.cs index 521bc00a7e..01248d5bbe 100644 --- a/samples/ChatSample/Startup.cs +++ b/samples/ChatSample/Startup.cs @@ -88,7 +88,7 @@ namespace ChatSample app.UseSignalR(routes => { - routes.MapHub("chat"); + routes.MapHub("/chat"); }); app.UseMvc(routes => diff --git a/samples/JwtSample/Startup.cs b/samples/JwtSample/Startup.cs index 63887aa920..54ae6be7f9 100644 --- a/samples/JwtSample/Startup.cs +++ b/samples/JwtSample/Startup.cs @@ -66,7 +66,7 @@ namespace JwtSample public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseFileServer(); - app.UseSignalR(options => options.MapHub("broadcast")); + app.UseSignalR(options => options.MapHub("/broadcast")); var routeBuilder = new RouteBuilder(app); routeBuilder.MapGet("generatetoken", c => c.Response.WriteAsync(GenerateToken(c))); diff --git a/samples/SocialWeather/Startup.cs b/samples/SocialWeather/Startup.cs index fa2d62bb43..1621ee6a66 100644 --- a/samples/SocialWeather/Startup.cs +++ b/samples/SocialWeather/Startup.cs @@ -32,7 +32,7 @@ namespace SocialWeather app.UseDeveloperExceptionPage(); } - app.UseSockets(o => { o.MapEndPoint("weather"); }); + app.UseSockets(o => { o.MapEndPoint("/weather"); }); app.UseFileServer(); var formatterResolver = app.ApplicationServices.GetRequiredService(); diff --git a/samples/SocketsSample/Startup.cs b/samples/SocketsSample/Startup.cs index bc6096a19f..d4ce58a59a 100644 --- a/samples/SocketsSample/Startup.cs +++ b/samples/SocketsSample/Startup.cs @@ -52,15 +52,15 @@ namespace SocketsSample app.UseSignalR(routes => { - routes.MapHub("dynamic"); - routes.MapHub("default"); - routes.MapHub("streaming"); - routes.MapHub("hubT"); + routes.MapHub("/dynamic"); + routes.MapHub("/default"); + routes.MapHub("/streaming"); + routes.MapHub("/hubT"); }); app.UseSockets(routes => { - routes.MapEndPoint("chat"); + routes.MapEndPoint("/chat"); }); } } diff --git a/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs b/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs index 2224d54631..97463258e9 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubRouteBuilder.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Sockets; namespace Microsoft.AspNetCore.SignalR @@ -18,11 +19,16 @@ namespace Microsoft.AspNetCore.SignalR } public void MapHub(string path) where THub : Hub + { + MapHub(new PathString(path), socketOptions: null); + } + + public void MapHub(PathString path) where THub : Hub { MapHub(path, socketOptions: null); } - public void MapHub(string path, Action socketOptions) where THub : Hub + public void MapHub(PathString path, Action socketOptions) where THub : Hub { // find auth attributes var authorizeAttributes = typeof(THub).GetCustomAttributes(inherit: true); diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs index 7dfa0654f9..99b92af5d5 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs @@ -4,6 +4,7 @@ using System; using System.Reflection; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Sockets @@ -20,9 +21,12 @@ namespace Microsoft.AspNetCore.Sockets } public void MapSocket(string path, Action socketConfig) => + MapSocket(new PathString(path), new HttpSocketOptions(), socketConfig); + + public void MapSocket(PathString path, Action socketConfig) => MapSocket(path, new HttpSocketOptions(), socketConfig); - public void MapSocket(string path, HttpSocketOptions options, Action socketConfig) + public void MapSocket(PathString path, HttpSocketOptions options, Action socketConfig) { var socketBuilder = new SocketBuilder(_routes.ServiceProvider); socketConfig(socketBuilder); @@ -32,11 +36,16 @@ namespace Microsoft.AspNetCore.Sockets } public void MapEndPoint(string path) where TEndPoint : EndPoint + { + MapEndPoint(new PathString(path), socketOptions: null); + } + + public void MapEndPoint(PathString path) where TEndPoint : EndPoint { MapEndPoint(path, socketOptions: null); } - public void MapEndPoint(string path, Action socketOptions) where TEndPoint : EndPoint + public void MapEndPoint(PathString path, Action socketOptions) where TEndPoint : EndPoint { var authorizeAttributes = typeof(TEndPoint).GetCustomAttributes(inherit: true); var options = new HttpSocketOptions(); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs index fe5aa3cdc8..348c1b7288 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/Startup.cs @@ -49,10 +49,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests app.UseSignalR(routes => { - routes.MapHub("default"); - routes.MapHub("dynamic"); - routes.MapHub("hubT"); - routes.MapHub("authorizedhub"); + routes.MapHub("/default"); + routes.MapHub("/dynamic"); + routes.MapHub("/hubT"); + routes.MapHub("/authorizedhub"); }); app.Run(async (context) => diff --git a/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Startup.cs index 9bd63f655b..149c1a4749 100644 --- a/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Redis.Tests/Startup.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests public void Configure(IApplicationBuilder app, IHostingEnvironment env) { - app.UseSignalR(options => options.MapHub("echo")); + app.UseSignalR(options => options.MapHub("/echo")); } } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs index 5cc66c6928..9308e71653 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/MapSignalRTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { var ex = Assert.Throws(() => { - using (var builder = BuildWebHost(options => options.MapHub("overloads"))) + using (var builder = BuildWebHost(options => options.MapHub("/overloads"))) { builder.Start(); } @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubFindsAuthAttributeOnHub() { var authCount = 0; - using (var builder = BuildWebHost(options => options.MapHub("path", httpSocketOptions => + using (var builder = BuildWebHost(options => options.MapHub("/path", httpSocketOptions => { authCount += httpSocketOptions.AuthorizationData.Count; }))) @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubFindsAuthAttributeOnInheritedHub() { var authCount = 0; - using (var builder = BuildWebHost(options => options.MapHub("path", httpSocketOptions => + using (var builder = BuildWebHost(options => options.MapHub("/path", httpSocketOptions => { authCount += httpSocketOptions.AuthorizationData.Count; }))) @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub() { var authCount = 0; - using (var builder = BuildWebHost(options => options.MapHub("path", httpSocketOptions => + using (var builder = BuildWebHost(options => options.MapHub("/path", httpSocketOptions => { authCount += httpSocketOptions.AuthorizationData.Count; }))) diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs index 6ac1f383ad..4345ca24d1 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Startup.cs @@ -18,8 +18,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests public void Configure(IApplicationBuilder app, IHostingEnvironment env) { - app.UseSockets(options => options.MapEndPoint("echo")); - app.UseSignalR(options => options.MapHub("uncreatable")); + app.UseSockets(options => options.MapEndPoint("/echo")); + app.UseSignalR(options => options.MapHub("/uncreatable")); } } } diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs index 3db299c072..1b5b55ccb1 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/MapEndPointTests.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests public void MapEndPointFindsAuthAttributeOnEndPoint() { var authCount = 0; - using (var builder = BuildWebHost("auth", + using (var builder = BuildWebHost("/auth", options => authCount += options.AuthorizationData.Count)) { builder.Start(); @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests public void MapEndPointFindsAuthAttributeOnInheritedEndPoint() { var authCount = 0; - using (var builder = BuildWebHost("auth", + using (var builder = BuildWebHost("/auth", options => authCount += options.AuthorizationData.Count)) { builder.Start(); @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests public void MapEndPointFindsAuthAttributesOnDoubleAuthEndPoint() { var authCount = 0; - using (var builder = BuildWebHost("auth", + using (var builder = BuildWebHost("/auth", options => authCount += options.AuthorizationData.Count)) { builder.Start(); @@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests [OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")] public async Task MapEndPointWithWebSocketSubProtocolSetsProtocol() { - var host = BuildWebHost("socket", + var host = BuildWebHost("/socket", options => options.WebSockets.SubProtocol = "protocol1"); await host.StartAsync();