Skip to content

Commit 94a6e13

Browse files
authored
Static files overhaul (#35967)
1 parent 57819c6 commit 94a6e13

File tree

398 files changed

+1161
-383781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+1161
-383781
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,11 @@
16471647
{
16481648
"source_path": "aspnetcore/fundamentals/handle-errors.md",
16491649
"redirect_url": "/aspnet/core/fundamentals/error-handling-api",
1650+
"redirect_document_id": false
1651+
},
1652+
{
1653+
"source_path": "aspnetcore/fundamentals/map-static-files.md",
1654+
"redirect_url": "/aspnet/core/fundamentals/static-files",
16501655
"redirect_document_id": false
16511656
}
16521657
]

aspnetcore/blazor/fundamentals/environments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ For app's running locally in development, the app defaults to the `Development`
8484

8585
:::moniker range="< aspnetcore-5.0"
8686

87-
For general guidance on ASP.NET Core app configuration, see <xref:fundamentals/environments>. For server-side app configuration with static files in environments other than the <xref:Microsoft.Extensions.Hosting.Environments.Development> environment during development and testing (for example, <xref:Microsoft.Extensions.Hosting.Environments.Staging>), see <xref:blazor/fundamentals/static-files#static-files-in-non-development-environments>.
87+
For general guidance on ASP.NET Core app configuration, see <xref:fundamentals/environments>. For server-side app configuration with static files in environments other than the <xref:Microsoft.Extensions.Hosting.Environments.Development> environment during development and testing (for example, <xref:Microsoft.Extensions.Hosting.Environments.Staging>), see <xref:fundamentals/static-files#static-files-in-non-development-environments>.
8888

8989
:::moniker-end
9090

aspnetcore/blazor/fundamentals/static-files.md

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to configure and manage static files for Blazor apps.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 11/12/2024
8+
ms.date: 09/02/2025
99
uid: blazor/fundamentals/static-files
1010
---
1111
# ASP.NET Core Blazor static files
@@ -16,7 +16,7 @@ This article describes Blazor app configuration for serving static files.
1616

1717
:::moniker range=">= aspnetcore-9.0"
1818

19-
For general information on serving static files with Map Static Assets routing endpoint conventions, see <xref:fundamentals/map-static-files> before reading this article.
19+
For general information on serving static files with Map Static Assets routing endpoint conventions, see <xref:fundamentals/static-files> before reading this article.
2020

2121
:::moniker-end
2222

@@ -53,7 +53,7 @@ Serving static assets is managed by either routing endpoint conventions or a mid
5353
Feature | API | .NET Version | Description
5454
--- | --- | :---: | ---
5555
Map Static Assets routing endpoint conventions | <xref:Microsoft.AspNetCore.Builder.StaticAssetsEndpointRouteBuilderExtensions.MapStaticAssets%2A> | .NET 9 or later | Optimizes the delivery of static assets to clients.
56-
Static Files Middleware | <xref:Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles%2A> | All .NET versions | Serves static assets to clients without the optimizations of Map Static Assets but useful for some tasks that Map Static Assets isn't capable of managing.
56+
Static File Middleware | <xref:Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles%2A> | All .NET versions | Serves static assets to clients without the optimizations of Map Static Assets but useful for some tasks that Map Static Assets isn't capable of managing.
5757

5858
Map Static Assets can replace <xref:Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles%2A> in most situations. However, Map Static Assets is optimized for serving the assets from known locations in the app at build and publish time. If the app serves assets from other locations, such as disk or embedded resources, <xref:Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles%2A> should be used.
5959

@@ -272,7 +272,7 @@ Any script in `index.html` with the fingerprint marker is fingerprinted by the f
272272

273273
## Fingerprint client-side static assets in Blazor Web Apps
274274

275-
For client-side rendering (CSR) in Blazor Web Apps (Interactive Auto or Interactive WebAssembly render modes), static asset server-side [fingerprinting](https://wikipedia.org/wiki/Fingerprint_(computing)) is enabled by adopting [Map Static Assets routing endpoint conventions (`MapStaticAssets`)](xref:fundamentals/map-static-files), [`ImportMap` component](xref:blazor/fundamentals/static-files#importmap-component), and the <xref:Microsoft.AspNetCore.Components.ComponentBase.Assets?displayProperty=nameWithType> property (`@Assets["..."]`). For more information, see <xref:fundamentals/map-static-files>.
275+
For client-side rendering (CSR) in Blazor Web Apps (Interactive Auto or Interactive WebAssembly render modes), static asset server-side [fingerprinting](https://wikipedia.org/wiki/Fingerprint_(computing)) is enabled by adopting [Map Static Assets routing endpoint conventions (`MapStaticAssets`)](xref:fundamentals/static-files), [`ImportMap` component](xref:blazor/fundamentals/static-files#importmap-component), and the <xref:Microsoft.AspNetCore.Components.ComponentBase.Assets?displayProperty=nameWithType> property (`@Assets["..."]`). For more information, see <xref:fundamentals/static-files>.
276276

277277
To fingerprint additional JavaScript modules for CSR, use the `<StaticWebAssetFingerprintPattern>` item in the app's project file (`.csproj`). In the following example, a fingerprint is added for all developer-supplied `.mjs` files in the app:
278278

@@ -344,22 +344,6 @@ Changing the value (`Default`) of `<StaticWebAssetProjectMode>` or removing the
344344

345345
:::moniker-end
346346

347-
## Static files in non-`Development` environments
348-
349-
*This section applies to server-side static files.*
350-
351-
When running an app locally, static web assets are only enabled in the <xref:Microsoft.Extensions.Hosting.Environments.Development> environment. To enable static files for environments other than <xref:Microsoft.Extensions.Hosting.Environments.Development> during local development and testing (for example, <xref:Microsoft.Extensions.Hosting.Environments.Staging>), call <xref:Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseStaticWebAssets%2A> on the <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder> in the `Program` file.
352-
353-
> [!WARNING]
354-
> Call <xref:Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.UseStaticWebAssets%2A> for the ***exact environment*** to prevent activating the feature in production, as it serves files from separate locations on disk *other than from the project* if called in a production environment. The example in this section checks for the <xref:Microsoft.Extensions.Hosting.Environments.Staging> environment by calling <xref:Microsoft.Extensions.Hosting.HostEnvironmentEnvExtensions.IsStaging%2A>.
355-
356-
```csharp
357-
if (builder.Environment.IsStaging())
358-
{
359-
builder.WebHost.UseStaticWebAssets();
360-
}
361-
```
362-
363347
:::moniker range=">= aspnetcore-8.0"
364348

365349
## Prefix for Blazor WebAssembly assets
@@ -462,41 +446,12 @@ In the preceding examples, the `{TFM}` placeholder is the [Target Framework Moni
462446

463447
:::moniker-end
464448

449+
:::moniker range="< aspnetcore-8.0"
450+
465451
## File mappings and static file options
466452

467453
*This section applies to server-side static files.*
468454

469-
:::moniker range=">= aspnetcore-8.0"
470-
471-
To create additional file mappings with a <xref:Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider> or configure other <xref:Microsoft.AspNetCore.Builder.StaticFileOptions>, use **one** of the following approaches. In the following examples, the `{EXTENSION}` placeholder is the file extension, and the `{CONTENT TYPE}` placeholder is the content type. The namespace for the following API is <xref:Microsoft.AspNetCore.StaticFiles>.
472-
473-
* Configure options through [dependency injection (DI)](xref:blazor/fundamentals/dependency-injection) in the `Program` file using <xref:Microsoft.AspNetCore.Builder.StaticFileOptions>:
474-
475-
```csharp
476-
var provider = new FileExtensionContentTypeProvider();
477-
provider.Mappings["{EXTENSION}"] = "{CONTENT TYPE}";
478-
479-
builder.Services.Configure<StaticFileOptions>(options =>
480-
{
481-
options.ContentTypeProvider = provider;
482-
});
483-
484-
app.UseStaticFiles();
485-
```
486-
487-
* Pass the <xref:Microsoft.AspNetCore.Builder.StaticFileOptions> directly to <xref:Microsoft.AspNetCore.Builder.StaticFileExtensions.UseStaticFiles%2A> in the `Program` file:
488-
489-
```csharp
490-
var provider = new FileExtensionContentTypeProvider();
491-
provider.Mappings["{EXTENSION}"] = "{CONTENT TYPE}";
492-
493-
app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });
494-
```
495-
496-
:::moniker-end
497-
498-
:::moniker range="< aspnetcore-8.0"
499-
500455
To create additional file mappings with a <xref:Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider> or configure other <xref:Microsoft.AspNetCore.Builder.StaticFileOptions>, use **one** of the following approaches. In the following examples, the `{EXTENSION}` placeholder is the file extension, and the `{CONTENT TYPE}` placeholder is the content type.
501456

502457
* Configure options through [dependency injection (DI)](xref:blazor/fundamentals/dependency-injection) in the `Program` file using <xref:Microsoft.AspNetCore.Builder.StaticFileOptions>:

aspnetcore/client-side/spa/includes/intro6-7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
The Single Page Application (SPA) templates for [Angular](https://angular.dev/) and [React](https://reactjs.org/) offer the ability to develop Angular and React apps that are hosted inside a .NET backend server.
77

8-
At publish time, the files of the Angular and React app are copied to the `wwwroot` folder and are served via the [static files middleware](xref:fundamentals/static-files).
8+
At publish time, the files of the Angular and React app are copied to the `wwwroot` folder and are served via the [Static File Middleware](xref:fundamentals/static-files).
99

1010
Rather than returning HTTP 404 (Not Found), a fallback route handles unknown requests to the backend and serves the `index.html` for the SPA.
1111

0 commit comments

Comments
 (0)