|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 | 4 | using Microsoft.AspNetCore.Builder;
|
| 5 | +using Microsoft.AspNetCore.Hosting; |
5 | 6 | using Microsoft.AspNetCore.Http;
|
6 | 7 | using Microsoft.Extensions.Configuration;
|
7 | 8 | using Microsoft.Extensions.DependencyInjection;
|
@@ -29,27 +30,28 @@ public static void Configure(IApplicationBuilder app, IConfiguration configurati
|
29 | 30 |
|
30 | 31 | app.UseWebAssemblyDebugging();
|
31 | 32 |
|
32 |
| - bool applyCopHeaders = configuration.GetValue<bool>("ApplyCopHeaders"); |
| 33 | + var webHostEnvironment = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>(); |
| 34 | + var applyCopHeaders = configuration.GetValue<bool>("ApplyCopHeaders"); |
33 | 35 |
|
34 |
| - if (applyCopHeaders) |
| 36 | + app.Use(async (ctx, next) => |
35 | 37 | {
|
36 |
| - app.Use(async (ctx, next) => |
| 38 | + if (ctx.Request.Path.StartsWithSegments("/_framework/blazor.boot.json")) |
37 | 39 | {
|
38 |
| - if (ctx.Request.Path.StartsWithSegments("/_framework") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.server.js") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.web.js")) |
| 40 | + ctx.Response.Headers.Append("Blazor-Environment", webHostEnvironment.EnvironmentName); |
| 41 | + } |
| 42 | + else if (applyCopHeaders && ctx.Request.Path.StartsWithSegments("/_framework") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.server.js") && !ctx.Request.Path.StartsWithSegments("/_framework/blazor.web.js")) |
| 43 | + { |
| 44 | + var fileExtension = Path.GetExtension(ctx.Request.Path); |
| 45 | + if (string.Equals(fileExtension, ".js", StringComparison.OrdinalIgnoreCase)) |
39 | 46 | {
|
40 |
| - string fileExtension = Path.GetExtension(ctx.Request.Path); |
41 |
| - if (string.Equals(fileExtension, ".js")) |
42 |
| - { |
43 |
| - // Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer. |
44 |
| - ApplyCrossOriginPolicyHeaders(ctx); |
45 |
| - } |
| 47 | + // Browser multi-threaded runtime requires cross-origin policy headers to enable SharedArrayBuffer. |
| 48 | + ApplyCrossOriginPolicyHeaders(ctx); |
46 | 49 | }
|
| 50 | + } |
47 | 51 |
|
48 |
| - await next(ctx); |
49 |
| - }); |
50 |
| - } |
| 52 | + await next(ctx); |
| 53 | + }); |
51 | 54 |
|
52 |
| - //app.UseBlazorFrameworkFiles(); |
53 | 55 | app.UseRouting();
|
54 | 56 |
|
55 | 57 | app.UseStaticFiles(new StaticFileOptions
|
|
0 commit comments