Skip to content

Commit 088710d

Browse files
authored
Merge pull request #36809 from dotnet/main
Merge to Live
2 parents 5120314 + a56e782 commit 088710d

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

aspnetcore/mvc/advanced/custom-model-binding.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
title: Custom Model Binding in ASP.NET Core
3+
ai-usage: ai-assisted
34
author: tdykstra
45
description: Learn how model binding allows controller actions to work directly with model types in ASP.NET Core.
56
ms.author: tdykstra
6-
ms.date: 04/03/2024
7+
ms.date: 02/23/2026
78
uid: mvc/advanced/custom-model-binding
89
---
910
# Custom Model Binding in ASP.NET Core
@@ -59,15 +60,15 @@ The following example shows how to use `ByteArrayModelBinder` to convert a base6
5960

6061
[!code-csharp[](custom-model-binding/samples/3.x/CustomModelBindingSample/Controllers/ImageController.cs?name=snippet_Post)]
6162

62-
You can POST a base64-encoded string to the previous api method using a tool like [curl](https://curl.haxx.se/).
63+
You can POST a base64-encoded string to the previous API method using a tool like [curl](https://curl.haxx.se/).
6364

6465
As long as the binder can bind request data to appropriately named properties or arguments, model binding will succeed. The following example shows how to use `ByteArrayModelBinder` with a view model:
6566

6667
[!code-csharp[](custom-model-binding/samples/3.x/CustomModelBindingSample/Controllers/ImageController.cs?name=snippet_SaveProfile&highlight=2)]
6768

6869
## Custom model binder sample
6970

70-
In this section we'll implement a custom model binder that:
71+
In this section, we'll implement a custom model binder that:
7172

7273
* Converts incoming request data into strongly typed key arguments.
7374
* Uses Entity Framework Core to fetch the associated entity.
@@ -79,12 +80,12 @@ The following sample uses the `ModelBinder` attribute on the `Author` model:
7980

8081
In the preceding code, the `ModelBinder` attribute specifies the type of `IModelBinder` that should be used to bind `Author` action parameters.
8182

82-
The following `AuthorEntityBinder` class binds an `Author` parameter by fetching the entity from a data source using Entity Framework Core and an `authorId`:
83+
The following `AuthorEntityBinder` class binds an `Author` parameter by using the `author` route value to fetch the entity from a data source with Entity Framework Core:
8384

8485
[!code-csharp[](custom-model-binding/samples/3.x/CustomModelBindingSample/Binders/AuthorEntityBinder.cs?name=snippet_Class)]
8586

8687
> [!NOTE]
87-
> The preceding `AuthorEntityBinder` class is intended to illustrate a custom model binder. The class isn't intended to illustrate best practices for a lookup scenario. For lookup, bind the `authorId` and query the database in an action method. This approach separates model binding failures from `NotFound` cases.
88+
> The preceding `AuthorEntityBinder` class is intended to illustrate a custom model binder. The class isn't intended to illustrate best practices for a lookup scenario. For lookup, bind the `author` parameter directly and query the database in an action method. This approach separates model binding failures from `NotFound` cases.
8889
8990
The following code shows how to use the `AuthorEntityBinder` in an action method:
9091

@@ -94,7 +95,7 @@ The `ModelBinder` attribute can be used to apply the `AuthorEntityBinder` to par
9495

9596
[!code-csharp[](custom-model-binding/samples/3.x/CustomModelBindingSample/Controllers/BoundAuthorsController.cs?name=snippet_GetById&highlight=2)]
9697

97-
In this example, since the name of the argument isn't the default `authorId`, it's specified on the parameter using the `ModelBinder` attribute. Both the controller and action method are simplified compared to looking up the entity in the action method. The logic to fetch the author using Entity Framework Core is moved to the model binder. This can be a considerable simplification when you have several methods that bind to the `Author` model.
98+
In this example, since the route parameter name (`id`) doesn't match the action method parameter name (`author`), the `Name` property on the `ModelBinder` attribute is used to specify which route value to bind. Both the controller and action method are simplified compared to looking up the entity in the action method. The logic to fetch the author using Entity Framework Core is moved to the model binder. This can be a considerable simplification when you have several methods that bind to the `Author` model.
9899

99100
You can apply the `ModelBinder` attribute to individual model properties (such as on a viewmodel) or to action method parameters to specify a certain model binder or model name for just that type or action.
100101

@@ -104,7 +105,7 @@ Instead of applying an attribute, you can implement `IModelBinderProvider`. This
104105

105106
[!code-csharp[](custom-model-binding/samples/3.x/CustomModelBindingSample/Binders/AuthorEntityBinderProvider.cs?highlight=17-20)]
106107

107-
> Note:
108+
> [!NOTE]
108109
> The preceding code returns a `BinderTypeModelBinder`. `BinderTypeModelBinder` acts as a factory for model binders and provides dependency injection (DI). The `AuthorEntityBinder` requires DI to access EF Core. Use `BinderTypeModelBinder` if your model binder requires services from DI.
109110
110111
To use a custom model binder provider, add it in `ConfigureServices`:
@@ -200,12 +201,12 @@ The following sample uses the `ModelBinder` attribute on the `Author` model:
200201

201202
In the preceding code, the `ModelBinder` attribute specifies the type of `IModelBinder` that should be used to bind `Author` action parameters.
202203

203-
The following `AuthorEntityBinder` class binds an `Author` parameter by fetching the entity from a data source using Entity Framework Core and an `authorId`:
204+
The following `AuthorEntityBinder` class binds an `Author` parameter by fetching the entity from a data source using Entity Framework Core and an `author` route value:
204205

205206
[!code-csharp[](custom-model-binding/samples/2.x/CustomModelBindingSample/Binders/AuthorEntityBinder.cs?name=demo)]
206207

207208
> [!NOTE]
208-
> The preceding `AuthorEntityBinder` class is intended to illustrate a custom model binder. The class isn't intended to illustrate best practices for a lookup scenario. For lookup, bind the `authorId` and query the database in an action method. This approach separates model binding failures from `NotFound` cases.
209+
> The preceding `AuthorEntityBinder` class is intended to illustrate a custom model binder. The class isn't intended to illustrate best practices for a lookup scenario. For lookup, bind the `author` parameter directly and query the database in an action method. This approach separates model binding failures from `NotFound` cases.
209210
210211
The following code shows how to use the `AuthorEntityBinder` in an action method:
211212

@@ -215,7 +216,7 @@ The `ModelBinder` attribute can be used to apply the `AuthorEntityBinder` to par
215216

216217
[!code-csharp[](custom-model-binding/samples/2.x/CustomModelBindingSample/Controllers/BoundAuthorsController.cs?name=demo1&highlight=2)]
217218

218-
In this example, since the name of the argument isn't the default `authorId`, it's specified on the parameter using the `ModelBinder` attribute. Both the controller and action method are simplified compared to looking up the entity in the action method. The logic to fetch the author using Entity Framework Core is moved to the model binder. This can be a considerable simplification when you have several methods that bind to the `Author` model.
219+
In this example, since the route parameter name (`id`) doesn't match the action method parameter name (`author`), the `Name` property on the `ModelBinder` attribute is used to specify which route value to bind. Both the controller and action method are simplified compared to looking up the entity in the action method. The logic to fetch the author using Entity Framework Core is moved to the model binder. This can be a considerable simplification when you have several methods that bind to the `Author` model.
219220

220221
You can apply the `ModelBinder` attribute to individual model properties (such as on a viewmodel) or to action method parameters to specify a certain model binder or model name for just that type or action.
221222

@@ -225,7 +226,7 @@ Instead of applying an attribute, you can implement `IModelBinderProvider`. This
225226

226227
[!code-csharp[](custom-model-binding/samples/2.x/CustomModelBindingSample/Binders/AuthorEntityBinderProvider.cs?highlight=17-20)]
227228

228-
> Note:
229+
> [!NOTE]
229230
> The preceding code returns a `BinderTypeModelBinder`. `BinderTypeModelBinder` acts as a factory for model binders and provides dependency injection (DI). The `AuthorEntityBinder` requires DI to access EF Core. Use `BinderTypeModelBinder` if your model binder requires services from DI.
230231
231232
To use a custom model binder provider, add it in `ConfigureServices`:

aspnetcore/tutorials/publish-to-iis.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22
title: Publish an ASP.NET Core app to IIS
3+
ai-usage: ai-assisted
34
author: wadepickett
45
description: Learn how to host an ASP.NET Core app on an IIS server.
5-
monikerRange: '>= aspnetcore-2.1'
6+
monikerRange: '>= aspnetcore-8.0'
67
ms.author: wpickett
78
ms.custom: mvc
8-
ms.date: 10/03/2019
9+
ms.date: 02/23/2026
910
uid: tutorials/publish-to-iis
1011
---
1112
# Publish an ASP.NET Core app to IIS
1213

13-
This tutorial shows how to host an ASP.NET Core app on an IIS server.
14+
Internet Information Services (IIS) is a flexible, general-purpose web server that runs on Windows and can host ASP.NET Core apps. IIS is a good choice when you need to run ASP.NET Core apps on Windows Server in an on-premises or hybrid environment, need Windows Authentication, or require integration with other IIS features such as URL Rewrite, Application Request Routing, or centralized certificate management.
1415

1516
This tutorial covers the following subjects:
1617

@@ -37,6 +38,8 @@ This tutorial covers the following subjects:
3738

3839
Install the *.NET Hosting Bundle* on the IIS server. The bundle installs the .NET Runtime, .NET Library, and the [ASP.NET Core Module](xref:host-and-deploy/aspnet-core-module). The module allows ASP.NET Core apps to run behind IIS.
3940

41+
ASP.NET Core apps hosted in IIS use the *in-process hosting model* by default (since ASP.NET Core 3.0). In-process hosting runs the app in the same process as the IIS worker process (`w3wp.exe`), which provides better performance than out-of-process hosting. For more information, see <xref:host-and-deploy/iis/index>.
42+
4043
Download the installer using the following link:
4144

4245
[Current .NET Hosting Bundle installer (direct download)](https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer)
@@ -74,14 +77,18 @@ Create any type of ASP.NET Core server-based app.
7477
* The app is published to a folder.
7578
* The folder's contents are moved to the IIS site's folder (the **Physical path** to the site in IIS Manager).
7679

80+
ASP.NET Core apps can be published as *framework-dependent* (the server must have .NET installed) or *self-contained* (includes the .NET runtime in the published output). For most IIS deployments, the framework-dependent approach is recommended because the .NET Hosting Bundle provides the required runtime on the server. For more information, see [.NET application deployment](/dotnet/core/deploying/).
81+
82+
A `web.config` file is generated automatically when the app is published. IIS uses this file to configure the ASP.NET Core Module for the app. Don't remove or manually edit the `web.config` file unless you're making advanced configuration changes.
83+
7784
# [Visual Studio](#tab/visual-studio)
7885

7986
1. Right-click on the project in **Solution Explorer** and select **Publish**.
80-
1. In the **Pick a publish target** dialog, select the **Folder** publish option.
81-
1. Set the **Folder or File Share** path.
87+
1. In the **Publish** dialog, select **Folder** as the publish target and select **Next**.
88+
1. Set the **Folder location** path.
8289
* If you created a folder for the IIS site that's available on the development machine as a network share, provide the path to the share. The current user must have write access to publish to the share.
83-
* If you're unable to deploy directly to the IIS site folder on the IIS server, publish to a folder on removable media and physically move the published app to the IIS site folder on the server, which is the site's **Physical path** in IIS Manager. Move the contents of the `bin/Release/{TARGET FRAMEWORK}/publish` folder to the IIS site folder on the server, which is the site's **Physical path** in IIS Manager.
84-
1. Select the **Publish** button.
90+
* If you're unable to deploy directly to the IIS site folder on the IIS server, publish to a folder on removable media and physically move the published app to the IIS site folder on the server, which is the site's **Physical path** in IIS Manager. Move the contents of the `bin/Release/{TARGET FRAMEWORK}/publish` folder (where `{TARGET FRAMEWORK}` is the target framework moniker, for example `net10.0`) to the IIS site folder on the server, which is the site's **Physical path** in IIS Manager.
91+
1. Select **Finish** and then select **Publish**.
8592

8693
# [.NET CLI](#tab/net-cli)
8794

@@ -91,7 +98,7 @@ Create any type of ASP.NET Core server-based app.
9198
dotnet publish --configuration Release
9299
```
93100

94-
1. Move the contents of the `bin/Release/{TARGET FRAMEWORK}/publish` folder to the IIS site folder on the server, which is the site's **Physical path** in IIS Manager.
101+
1. Move the contents of the `bin/Release/{TARGET FRAMEWORK}/publish` folder (where `{TARGET FRAMEWORK}` is the target framework moniker, for example `net10.0`) to the IIS site folder on the server, which is the site's **Physical path** in IIS Manager.
95102

96103
---
97104

@@ -144,9 +151,6 @@ To learn more about hosting ASP.NET Core apps on IIS, see the IIS Overview artic
144151
* [IIS documentation](/iis)
145152
* [Getting Started with the IIS Manager in IIS](/iis/get-started/getting-started-with-iis/getting-started-with-the-iis-manager-in-iis-7-and-iis-8)
146153
* [.NET application deployment](/dotnet/core/deploying/)
147-
* <xref:host-and-deploy/aspnet-core-module>
148-
* <xref:host-and-deploy/directory-structure>
149154
* <xref:host-and-deploy/iis/modules>
150-
* <xref:test/troubleshoot-azure-iis>
151155
* <xref:host-and-deploy/azure-iis-errors-reference>
152156
* [Sticky sessions with Application Request Routing](/iis/extensions/configuring-application-request-routing-arr/http-load-balancing-using-application-request-routing)

0 commit comments

Comments
 (0)