diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 03d1776b0469..a965b409e8fe 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -982,22 +982,22 @@ }, { "source_path": "aspnetcore/migration/proper-to-2x/membership-to-core-identity.md", - "redirect_url": "migration/fx-to-core/areas/membership/", + "redirect_url": "/aspnet/core/migration/fx-to-core/areas/membership/", "redirect_document_id": false }, { "source_path": "aspnetcore/migration/proper-to-2x/mvc2.md", - "redirect_url": "migration/fx-to-core/areas/mvc/", + "redirect_url": "/aspnet/core/migration/fx-to-core/areas/mvc/", "redirect_document_id": false }, { "source_path": "aspnetcore/migration/mvc.md", - "redirect_url": "migration/fx-to-core/tooling", + "redirect_url": "/aspnet/core/migration/fx-to-core/tooling", "redirect_document_id": false }, { "source_path": "aspnetcore/migration/web_forms.md", - "redirect_url": "migration/fx-to-core/tooling", + "redirect_url": "/aspnet/core/migration/fx-to-core/tooling", "redirect_document_id": false }, { @@ -1567,6 +1567,11 @@ "source_path": "aspnetcore/blazor/progressive-web-app.md", "redirect_url": "/aspnet/core/blazor/progressive-web-app/", "redirect_document_id": false + }, + { + "source_path": "aspnetcore/getting-started/index.md", + "redirect_url": "/aspnet/core/get-started", + "redirect_document_id": false } ] } diff --git a/aspnetcore/_static/toc-selector.png b/aspnetcore/_static/toc-selector.png deleted file mode 100644 index a922f1b828fb..000000000000 Binary files a/aspnetcore/_static/toc-selector.png and /dev/null differ diff --git a/aspnetcore/_static/version-selector.png b/aspnetcore/_static/version-selector.png deleted file mode 100644 index 393f5ac5ff72..000000000000 Binary files a/aspnetcore/_static/version-selector.png and /dev/null differ diff --git a/aspnetcore/blazor/forms/validation.md b/aspnetcore/blazor/forms/validation.md index bc055d2ad2cd..d3462ca411bc 100644 --- a/aspnetcore/blazor/forms/validation.md +++ b/aspnetcore/blazor/forms/validation.md @@ -132,7 +132,7 @@ In the following component, the `HandleValidationRequested` handler method clear The component attaches data annotations validation to a cascaded . Enabling data annotations validation requires the component. To use a different validation system than data annotations, use a custom implementation instead of the component. The framework implementations for are available for inspection in the reference source: * [`DataAnnotationsValidator`](https://github.com/dotnet/AspNetCore/blob/main/src/Components/Forms/src/DataAnnotationsValidator.cs) -* [`AddDataAnnotationsValidation`](https://github.com/dotnet/AspNetCore/blob/main/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs) +* [`EnableDataAnnotationsValidation`](https://github.com/dotnet/AspNetCore/blob/main/src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs) If you need to enable data annotations validation support for an in code, call with an injected (`@inject IServiceProvider ServiceProvider`) on the . For an advanced example, see the [`NotifyPropertyChangedValidationComponent` component in the ASP.NET Core Blazor framework's `BasicTestApp` (`dotnet/aspnetcore` GitHub repository)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor). In a production version of the example, replace the `new TestServiceProvider()` argument for the service provider with an injected . diff --git a/aspnetcore/data/ef-rp/intro.md b/aspnetcore/data/ef-rp/intro.md index 3b1f3a328b1d..5838bba4f66a 100644 --- a/aspnetcore/data/ef-rp/intro.md +++ b/aspnetcore/data/ef-rp/intro.md @@ -8,7 +8,6 @@ ms.custom: "mvc" ms.date: 04/23/2025 uid: data/ef-rp/intro --- - # Razor Pages with Entity Framework Core in ASP.NET Core - Tutorial 1 of 8 [!INCLUDE[](~/includes/not-latest-version.md)] diff --git a/aspnetcore/fundamentals/index.md b/aspnetcore/fundamentals/index.md index 9c7afc79f800..2de2dc70567d 100644 --- a/aspnetcore/fundamentals/index.md +++ b/aspnetcore/fundamentals/index.md @@ -5,7 +5,7 @@ description: Learn the fundamental concepts for building ASP.NET Core apps, incl monikerRange: '>= aspnetcore-3.1' ms.author: tdykstra ms.custom: mvc -ms.date: 08/01/2024 +ms.date: 07/23/2025 uid: fundamentals/index --- # ASP.NET Core fundamentals overview @@ -210,9 +210,9 @@ The content root is the base path for: * Razor files (`.cshtml`, `.razor`) * Configuration files (`.json`, `.xml`) * Data files (`.db`) -* The [Web root](#web-root), typically the *wwwroot* folder. +* The [Web root](#web-root), typically the `wwwroot` folder. -During development, the content root defaults to the project's root directory. This directory is also the base path for both the app's content files and the [Web root](#web-root). Specify a different content root by setting its path when [building the host](#host). For more information, see [Content root](xref:fundamentals/host/generic-host#contentroot). +During development, the content root defaults to the project's root directory. This directory is also the base path for both the app's content files and the [web root](#web-root). Specify a different content root by setting its path when [building the host](#host). For more information, see [Content root](xref:fundamentals/host/generic-host#contentroot). ## Web root @@ -222,9 +222,9 @@ The web root is the base path for public, static resource files, such as: * JavaScript (`.js`) * Images (`.png`, `.jpg`) -By default, static files are served only from the web root directory and its sub-directories. The web root path defaults to *{content root}/wwwroot*. Specify a different web root by setting its path when [building the host](#host). For more information, see [Web root](xref:fundamentals/host/generic-host#webroot). +By default, static files are served only from the web root directory and its sub-directories. The web root path defaults to `{CONTENT ROOT}/wwwroot`, where the `{CONTENT ROOT}` placeholder is the content root. Specify a different web root by setting its path when [building the host](#host). For more information, see [Web root](xref:fundamentals/host/generic-host#webroot). -Prevent publishing files in *wwwroot* with the [\ project item](/visualstudio/msbuild/common-msbuild-project-items#content) in the project file. The following example prevents publishing content in *wwwroot/local* and its sub-directories: +Prevent publishing files in `wwwroot` with the [`` project item](/visualstudio/msbuild/common-msbuild-project-items#content) in the project file. The following example prevents publishing content in `wwwroot/local` and its sub-directories: ```xml diff --git a/aspnetcore/fundamentals/map-static-files.md b/aspnetcore/fundamentals/map-static-files.md index c6f7f1e794ea..8cdc03b32808 100644 --- a/aspnetcore/fundamentals/map-static-files.md +++ b/aspnetcore/fundamentals/map-static-files.md @@ -1,11 +1,11 @@ --- title: Map static files in ASP.NET Core -author: rick-anderson +author: guardrex description: Learn how to serve and secure mapped static files and configure static file hosting middleware behaviors in an ASP.NET Core web app. monikerRange: '>= aspnetcore-9.0' -ms.author: riande +ms.author: wpickett ms.custom: mvc -ms.date: 06/09/2025 +ms.date: 07/23/2025 uid: fundamentals/map-static-files --- # Map static files in ASP.NET Core @@ -16,40 +16,21 @@ uid: fundamentals/map-static-files --> -By [Rick Anderson](https://twitter.com/RickAndMSFT) - Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients by default. For Blazor static files guidance, which adds to or supersedes the guidance in this article, see . -## Serve static files - -Static files are stored within the project's [web root](xref:fundamentals/index#web-root) directory. The default directory is `{content root}/wwwroot`, but it can be changed with the method. For more information, see [Content root](xref:fundamentals/index#content-root) and [Web root](xref:fundamentals/index#web-root). - -The method sets the content root to the current directory: - -[!code-csharp[](~/fundamentals/static-files/samples/9.x/StaticFilesSample/Program.cs?name=snippet&highlight=1,15)] - -Static files are accessible via a path relative to the [web root](xref:fundamentals/index#web-root). For example, the **Web Application** project templates contain several folders within the `wwwroot` folder: - -* `wwwroot` - * `css` - * `js` - * `lib` - -Consider an app with the `wwwroot/images/MyImage.jpg` file. The URI format to access a file in the `images` folder is `https:///images/`. For example, `https://localhost:5001/images/MyImage.jpg` - ### Map Static Assets routing endpoint conventions (`MapStaticAssets`) Creating performant web apps requires optimizing asset delivery to the browser. Possible optimizations with include: -* Serve a given asset once until the file changes or the browser clears its cache. Set the [ETag](https://developer.mozilla.org/docs/Web/HTTP/Headers/ETag) and [Last-Modified](https://developer.mozilla.org/docs/Web/HTTP/Headers/Last-Modified) headers. -* Prevent the browser from using old or stale assets after an app is updated. Set the [Last-Modified](https://developer.mozilla.org/docs/Web/HTTP/Headers/Last-Modified) header. -* Set up proper [caching headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control). +* Serve a given asset once until the file changes or the browser clears its cache. Set the [`ETag`](https://developer.mozilla.org/docs/Web/HTTP/Headers/ETag) and [Last-Modified](https://developer.mozilla.org/docs/Web/HTTP/Headers/Last-Modified) headers. +* Prevent the browser from using old or stale assets after an app is updated. Set the [`Last-Modified`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Last-Modified) header. +* Set appropriate [caching headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control) on the response. * Use [Caching Middleware](xref:performance/caching/middleware). * Serve [compressed](/aspnet/core/performance/response-compression) versions of the assets when possible. This optimization doesn't include minification. * Use a [CDN](/microsoft-365/enterprise/content-delivery-networks?view=o365-worldwide&preserve-view=true) to serve the assets closer to the user. -* [Fingerprinting assets](https://en.wikipedia.org/wiki/Fingerprint_(computing)) to prevent reusing old versions of files. +* [Fingerprinting assets](https://wikipedia.org/wiki/Fingerprint_(computing)) to prevent reusing old versions of files. `MapStaticAssets`: @@ -78,13 +59,6 @@ Map Static Assets doesn't provide features for minification or other file transf The following features are supported with `UseStaticFiles` but not with `MapStaticAssets`: -* [Serving files from disk or embedded resources, or other locations](xref:fundamentals/static-files#serve-files-from-multiple-locations) -* [Serve files outside of web root](xref:fundamentals/static-files#serve-files-outside-of-web-root) -* [Set HTTP response headers](xref:fundamentals/static-files#set-http-response-headers) -* [Directory browsing](xref:fundamentals/static-files#directory-browsing) -* [Serve default documents](xref:fundamentals/static-files#serve-default-documents) -* [`FileExtensionContentTypeProvider`](xref:fundamentals/static-files#fileextensioncontenttypeprovider) -* [Serve files from multiple locations](xref:fundamentals/static-files#serve-files-from-multiple-locations) * [Serving files from disk or embedded resources, or other locations](xref:fundamentals/static-files#serve-files-from-multiple-locations) * [Serve files outside of web root](xref:fundamentals/static-files#serve-files-outside-of-web-root) * [Set HTTP response headers](xref:fundamentals/static-files#set-http-response-headers) @@ -95,21 +69,37 @@ The following features are supported with `UseStaticFiles` but not with `MapStat ### Serve files in web root -The default web app templates call the method in `Program.cs`, which enables static files to be served: +In the app's `Program` file, sets the [content root](xref:fundamentals/index#content-root) to the current directory. Call method to enable serving static files. The parameterless overload results in serving the files from the app's [web root](xref:fundamentals/index#web-root). The default web root directory is `{CONTENT ROOT}/wwwroot`, where the `{CONTENT ROOT}` placeholder is the content root. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +... + +app.MapStaticAssets(); +``` + +You can change the web root with the method. For more information, see the [Content root](xref:fundamentals/index#content-root) and [Web root](xref:fundamentals/index#web-root) sections of the *ASP.NET Core fundamentals overview* article. -[!code-csharp[](~/fundamentals/static-files/samples/9.x/StaticFilesSample/Program.cs?name=snippet&highlight=15)] +Static files are accessible via a path relative to the web root. For example, the Blazor Web App project template contains the `lib` folder within the `wwwroot` folder, which contains Bootstrap static assets. -The parameterless `MapStaticAssets` method overload marks the files in [web root](xref:fundamentals/index#web-root) as servable. The following markup references `wwwroot/images/MyImage.jpg`: +If an app placed its images in an `images` folder in `wwwroot`, the following markup references `wwwroot/images/favicon.png`: ```html -My image + +``` + +In Razor Pages and MVC apps (but not Blazor apps), the tilde character `~` points to the web root. In the following example, `~/images/icon.jpg` loads the icon image (`icon.jpg`) from the app's `wwwroot/images` folder: + +```cshtml +Icon image ``` -In the preceding markup, the tilde character `~` points to the [web root](xref:fundamentals/index#web-root). +The URL format for the preceding example is `https://{HOST}/images/{FILE NAME}`. The `{HOST}` placeholder is the host, and the `{FILE NAME}` placeholder is the file name. For the preceding example running at the app's localhost address on port 5001, the absolute URL is `https://localhost:5001/images/icon.jpg`. ### Serve files outside of web root -Consider a directory hierarchy in which the static files to be served reside outside of the [web root](xref:fundamentals/index#web-root): +Consider the following directory hierarchy with static files residing outside of the app's [web root](xref:fundamentals/index#web-root) in a folder named `MyStaticFiles`: * `wwwroot` * `css` @@ -121,19 +111,19 @@ Consider a directory hierarchy in which the static files to be served reside out A request can access the `red-rose.jpg` file by configuring the Static File Middleware as follows: -[!code-csharp[](~/fundamentals/static-files/samples/9.x/StaticFilesSample/Program.cs?name=snippet_rr&highlight=1,18-23)] +[!code-csharp[](~/fundamentals/static-files/samples/9.x/StaticFilesSample/Program.cs?name=snippet_rr&highlight=1,18-24)] -In the preceding code, the *MyStaticFiles* directory hierarchy is exposed publicly via the *StaticFiles* URI segment. A request to `https:///StaticFiles/images/red-rose.jpg` serves the `red-rose.jpg` file. +In the preceding code, the `MyStaticFiles` directory hierarchy is exposed publicly via the `StaticFiles` URL segment. A request to `https://{HOST}/StaticFiles/images/red-rose.jpg`, where the `{HOST}` placeholder is the host, serves the `red-rose.jpg` file. The following markup references `MyStaticFiles/images/red-rose.jpg`: - + [!code-html[](~/fundamentals/static-files/samples/9.x/StaticFilesSample/Views/Home2/MyStaticFilesRR.cshtml?range=1)] To serve files from multiple locations, see [Serve files from multiple locations](xref:fundamentals/static-files#serve-files-from-multiple-locations). ### Set HTTP response headers -A object can be used to set HTTP response headers. In addition to configuring static file serving from the [web root](xref:fundamentals/index#web-root), the following code sets the [Cache-Control](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control) header: +A object can be used to set HTTP response headers. In addition to configuring the middleware to serve static files from the [web root](xref:fundamentals/index#web-root), the following code sets the [`Cache-Control`](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control) header: [!code-csharp[](~/fundamentals/static-files/samples/9.x/StaticFilesSample/Program.cs?name=snippet_rh&highlight=16-24)] @@ -143,9 +133,9 @@ The preceding code makes static files publicly available in the local cache for The ASP.NET Core templates call before calling . Most apps follow this pattern. When `MapStaticAssets` is called before the authorization middleware: - * No authorization checks are performed on the static files. - * Static files served by the Static File Middleware, such as those under `wwwroot`, are publicly accessible. - +* No authorization checks are performed on the static files. +* Static files served by the Static File Middleware, such as those under `wwwroot`, are publicly accessible. + To serve static files based on authorization, see [Static file authorization](xref:fundamentals/static-files#static-file-authorization). ## Serve files from multiple locations @@ -161,7 +151,7 @@ Consider the following Razor page which displays the `/MyStaticFiles/image3.png` Using the preceding code: * The `/MyStaticFiles/image3.png` file is displayed. -* The [Image Tag Helpers](xref:mvc/views/tag-helpers/builtin-th/image-tag-helper) is not applied because the Tag Helpers depend on . `WebRootFileProvider` has not been updated to include the `MyStaticFiles` folder. +* [Image Tag Helpers](xref:mvc/views/tag-helpers/builtin-th/image-tag-helper) () aren't applied because Tag Helpers depend on . `WebRootFileProvider` hasn't been updated to include the `MyStaticFiles` folder. The following code updates the `WebRootFileProvider`, which enables the Image Tag Helper to provide a version: @@ -170,7 +160,7 @@ The following code updates the `WebRootFileProvider`, which enables the Image Ta > [!NOTE] > The preceding approach applies to Razor Pages and MVC apps. For guidance that applies to Blazor Web Apps, see . -## Serve files outside wwwroot by updating IWebHostEnvironment.WebRootPath +## Serve files outside wwwroot by updating `IWebHostEnvironment.WebRootPath` When is set to a folder other than `wwwroot`: @@ -186,8 +176,8 @@ Consider a web app created with the empty web template: In the preceding code, requests to `/`: -* In the development environment return `wwwroot/Index.html` -* In any environment other than development return `wwwroot-custom/Index.html` +* In the development environment, return `wwwroot/Index.html`. +* In any environment other than development, return `wwwroot-custom/Index.html`. To ensure assets from `wwwroot-custom` are returned, use one of the following approaches: @@ -202,14 +192,15 @@ To ensure assets from `wwwroot-custom` are returned, use one of the following ap ``` -The following code updates `IWebHostEnvironment.WebRootPath` to a non development value, guaranteeing duplicate content is returned from `wwwroot-custom` rather than `wwwroot`: +The following code updates `IWebHostEnvironment.WebRootPath` to a non-Development value (Staging), guaranteeing duplicate content is returned from `wwwroot-custom` rather than `wwwroot`: [!code-csharp[](~/fundamentals/static-files/samples/9.x/WebRoot/Program.cs?name=snippet2&highlight=5)] +When developing a server-side Blazor app and testing locally, see . + ## Additional resources * [View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/static-files/samples) ([how to download](xref:index#how-to-download-a-sample)) -* [Middleware](xref:fundamentals/middleware/index) -* [Introduction to ASP.NET Core](xref:index) +* * * diff --git a/aspnetcore/fundamentals/openapi/include-metadata.md b/aspnetcore/fundamentals/openapi/include-metadata.md index a6b8b37fa272..0b03bb1e2ce1 100644 --- a/aspnetcore/fundamentals/openapi/include-metadata.md +++ b/aspnetcore/fundamentals/openapi/include-metadata.md @@ -263,7 +263,7 @@ public class Todo : IBindableFromHttpContext If the endpoint doesn't define any parameters bound to the request body, use the extension method to specify the content type that the endpoint accepts. -If you specify multiple times, only metadata from the last one is used -- they aren't combined. +If you specify multiple times, only metadata from the last one is used -- they aren't combined. #### [Controllers](#tab/controllers) diff --git a/aspnetcore/fundamentals/servers/yarp/direct-forwarding.md b/aspnetcore/fundamentals/servers/yarp/direct-forwarding.md index 35d245e20124..fcde079d2cfa 100644 --- a/aspnetcore/fundamentals/servers/yarp/direct-forwarding.md +++ b/aspnetcore/fundamentals/servers/yarp/direct-forwarding.md @@ -9,7 +9,6 @@ ms.topic: article content_well_notification: AI-contribution ai-usage: ai-assisted --- - # YARP Direct Forwarding Some applications only need the ability to take a specific request and forward it to a specific destination. These applications do not need, or have addressed in other ways, the other features of the proxy like configuration discovery, routing, load balancing, etc.. @@ -37,11 +36,11 @@ It does not include: See [ReverseProxy.Direct.Sample](https://github.com/microsoft/reverse-proxy/tree/release/latest/samples/ReverseProxy.Direct.Sample) as a pre-built sample, or use the steps below. -### Create a new project +### Add the YARP Reverse Proxy NuGet package -Follow the [Getting Started](xref:getting-started) guide to create a project and add the Yarp.ReverseProxy nuget dependency. +Add the [`Yarp.ReverseProxy` NuGet package](https://www.nuget.org/packages/Yarp.ReverseProxy) to the project. -### Update Program.cs +### Update `Program.cs` In this example the IHttpForwarder is registered in DI, injected into the endpoint method, and used to forward requests from a specific route to `https://localhost:10000/prefix/`. diff --git a/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Index.cshtml b/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Index.cshtml index fe6fc318635c..c14085382c8a 100644 --- a/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Index.cshtml +++ b/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Index.cshtml @@ -1,4 +1,4 @@ -@page +@page @model IndexModel @{ ViewData["Title"] = "RP Home page"; @@ -6,5 +6,5 @@

RP pages Welcome

-

Learn about Directy browsing.

+

Learn about Directory browsing.

diff --git a/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Privacy.cshtml b/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Privacy.cshtml index c9aa449da6a8..5dcc9199c77f 100644 --- a/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Privacy.cshtml +++ b/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Privacy.cshtml @@ -7,9 +7,12 @@

RP: Use this page to detail your site's privacy policy.

-

The following inmage doesn't display with app.UseStaticFiles(new StaticFileOptions

+

The following image doesn't display with app.UseStaticFiles(new StaticFileOptions ...).

+ My image +

The following image requires:

+

 app.UseStaticFiles(new StaticFileOptions //
 {
diff --git a/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Shared/_Layout.cshtml b/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Shared/_Layout.cshtml
index 5439b24cb0d1..5f8f21479149 100644
--- a/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Shared/_Layout.cshtml
+++ b/aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSample/Pages/Shared/_Layout.cshtml
@@ -1,4 +1,4 @@
-
+
 
 
     
@@ -25,7 +25,7 @@
                         
-                                                
                         
-