Skip to content

Commit f976dce

Browse files
authored
Merge pull request #17938 from dotnet/master
2 parents 5547d92 + 408ebbd commit f976dce

7 files changed

Lines changed: 45 additions & 30 deletions

File tree

aspnetcore/tutorials/signalr-blazor-webassembly.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Create a chat app that uses ASP.NET Core SignalR with Blazor WebAss
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/16/2020
8+
ms.date: 04/21/2020
99
no-loc: [Blazor, SignalR]
1010
uid: tutorials/signalr-blazor-webassembly
1111
---
@@ -160,7 +160,7 @@ In the **BlazorSignalRApp.Server** project, create a *Hubs* (plural) folder and
160160

161161
[!code-csharp[](signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Server/Hubs/ChatHub.cs)]
162162

163-
## Add SignalR services and an endpoint for the SignalR hub
163+
## Add services and an endpoint for the SignalR hub
164164

165165
1. In the **BlazorSignalRApp.Server** project, open the *Startup.cs* file.
166166

@@ -170,15 +170,13 @@ In the **BlazorSignalRApp.Server** project, create a *Hubs* (plural) folder and
170170
using BlazorSignalRApp.Server.Hubs;
171171
```
172172

173-
1. Add the SignalR services to `Startup.ConfigureServices`:
173+
1. Add SignalR and Response Compression Middleware services to `Startup.ConfigureServices`:
174174

175-
```csharp
176-
services.AddSignalR();
177-
```
175+
[!code-csharp[](signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Server/Startup.cs?name=snippet_ConfigureServices&highlight=3,5-9)]
178176

179-
1. In `Startup.Configure` between the endpoints for the default controller route and the client-side fallback, add an endpoint for the hub:
177+
1. In `Startup.Configure` between the endpoints for controllers and the client-side fallback, add an endpoint for the hub:
180178

181-
[!code-csharp[](signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Server/Startup.cs?name=snippet&highlight=4)]
179+
[!code-csharp[](signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Server/Startup.cs?name=snippet_UseEndpoints&highlight=4)]
182180

183181
## Add Razor component code for chat
184182

@@ -194,7 +192,7 @@ In the **BlazorSignalRApp.Server** project, create a *Hubs* (plural) folder and
194192

195193
# [Visual Studio](#tab/visual-studio)
196194

197-
1. In **Solution Explorer**, select the **BlazorSignalRApp.Server** project. Press **Ctrl+F5** to run the app without debugging.
195+
1. In **Solution Explorer**, select the **BlazorSignalRApp.Server** project. Press <kbd>F5</kbd> to run the app with debugging or <kbd>Ctrl</kbd>+<kbd>F5</kbd> to run the app without debugging.
198196

199197
1. Copy the URL from the address bar, open another browser instance or tab, and paste the URL in the address bar.
200198

@@ -206,7 +204,13 @@ In the **BlazorSignalRApp.Server** project, create a *Hubs* (plural) folder and
206204

207205
# [Visual Studio Code](#tab/visual-studio-code)
208206

209-
1. Select **Debug** > **Run Without Debugging** from the toolbar.
207+
1. When VS Code offers to create a launch profile for the Server app (*.vscode/launch.json*), the `program` entry appears similar to the following to point to the app's assembly (`{APPLICATION NAME}.Server.dll`):
208+
209+
```json
210+
"program": "${workspaceFolder}/Server/bin/Debug/netcoreapp3.1/{APPLICATION NAME}.Server.dll"
211+
```
212+
213+
1. Press <kbd>F5</kbd> to run the app with debugging or <kbd>Ctrl</kbd>+<kbd>F5</kbd> to run the app without debugging.
210214

211215
1. Copy the URL from the address bar, open another browser instance or tab, and paste the URL in the address bar.
212216

@@ -218,7 +222,7 @@ In the **BlazorSignalRApp.Server** project, create a *Hubs* (plural) folder and
218222

219223
# [Visual Studio for Mac](#tab/visual-studio-mac)
220224

221-
1. In the **Solution** sidebar, select the **BlazorSignalRApp.Server** project. From the menu, select **Run** > **Start Without Debugging**.
225+
1. In the **Solution** sidebar, select the **BlazorSignalRApp.Server** project. Press <kbd>⌘</kbd>+<kbd>↩</kbd>** to run the app with debugging or <kbd>⌥</kbd>+<kbd>⌘</kbd>+<kbd>↩</kbd> to run the app without debugging.
222226

223227
1. Copy the URL from the address bar, open another browser instance or tab, and paste the URL in the address bar.
224228

aspnetcore/tutorials/signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Client/BlazorSignalRApp.Client.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.2.0-preview1.20073.1" />
10-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
11-
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
12-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
13-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.1" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview4.20210.8" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview4.20210.8" PrivateAssets="all" />
12+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="3.1.3" />
13+
<PackageReference Include="System.Net.Http.Json" Version="3.2.0-preview5.20210.3" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<ProjectReference Include="..\Shared\BlazorSignalRApp.Shared.csproj" />

aspnetcore/tutorials/signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Client/Pages/FetchData.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ else
4040

4141
protected override async Task OnInitializedAsync()
4242
{
43-
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("WeatherForecast");
43+
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
4444
}
4545

4646
}

aspnetcore/tutorials/signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Client/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
2+
using System.Net.Http;
23
using System.Collections.Generic;
34
using System.Threading.Tasks;
45
using System.Text;
5-
using Microsoft.AspNetCore.Blazor.Hosting;
6+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
67
using Microsoft.Extensions.DependencyInjection;
78

89
namespace BlazorSignalRApp.Client
@@ -14,6 +15,8 @@ public static async Task Main(string[] args)
1415
var builder = WebAssemblyHostBuilder.CreateDefault(args);
1516
builder.RootComponents.Add<App>("app");
1617

18+
builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
19+
1720
await builder.Build().RunAsync();
1821
}
1922
}

aspnetcore/tutorials/signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Client/_Imports.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using System.Net.Http
2+
@using System.Net.Http.Json
23
@using Microsoft.AspNetCore.Components.Forms
34
@using Microsoft.AspNetCore.Components.Routing
45
@using Microsoft.AspNetCore.Components.Web

aspnetcore/tutorials/signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Server/BlazorSignalRApp.Server.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="3.2.0-preview1.20073.1" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.0-preview4.20210.8" />
99
</ItemGroup>
1010

1111
<ItemGroup>

aspnetcore/tutorials/signalr-blazor-webassembly/samples/3.x/BlazorSignalRApp/Server/Startup.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
using BlazorSignalRApp.Server.Hubs;
1+
using System.Linq;
22
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.HttpsPolicy;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.AspNetCore.ResponseCompression;
6+
using Microsoft.Extensions.Configuration;
57
using Microsoft.Extensions.DependencyInjection;
68
using Microsoft.Extensions.Hosting;
7-
using System.Linq;
9+
using BlazorSignalRApp.Server.Hubs;
810

911
namespace BlazorSignalRApp.Server
1012
{
1113
public class Startup
1214
{
13-
// This method gets called by the runtime. Use this method to add services to the container.
14-
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
15+
#region snippet_ConfigureServices
1516
public void ConfigureServices(IServiceCollection services)
1617
{
1718
services.AddSignalR();
18-
services.AddMvc();
19+
services.AddControllersWithViews();
1920
services.AddResponseCompression(opts =>
2021
{
2122
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
2223
new[] { "application/octet-stream" });
2324
});
2425
}
26+
#endregion
2527

26-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
2728
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
2829
{
2930

@@ -32,20 +33,26 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3233
if (env.IsDevelopment())
3334
{
3435
app.UseDeveloperExceptionPage();
35-
app.UseBlazorDebugging();
36+
app.UseWebAssemblyDebugging();
37+
}
38+
else
39+
{
40+
app.UseExceptionHandler("/Error");
41+
app.UseHsts();
3642
}
3743

44+
app.UseHttpsRedirection();
45+
app.UseBlazorFrameworkFiles();
3846
app.UseStaticFiles();
39-
app.UseClientSideBlazorFiles<Client.Program>();
4047

4148
app.UseRouting();
4249

43-
#region snippet
50+
#region snippet_UseEndpoints
4451
app.UseEndpoints(endpoints =>
4552
{
46-
endpoints.MapDefaultControllerRoute();
53+
endpoints.MapControllers();
4754
endpoints.MapHub<ChatHub>("/chatHub");
48-
endpoints.MapFallbackToClientSideBlazor<Client.Program>("index.html");
55+
endpoints.MapFallbackToFile("index.html");
4956
});
5057
#endregion
5158
}

0 commit comments

Comments
 (0)