Skip to content

Commit 9265a25

Browse files
authored
Clarify when the InnerHandler must be assigned (#35417)
1 parent 7643528 commit 9265a25

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

aspnetcore/blazor/security/webassembly/additional-scenarios.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ public class CustomAuthorizationMessageHandler : AuthorizationMessageHandler
300300
}
301301
```
302302

303+
> [!NOTE]
304+
> In this section, the preceding message handler is used when a configured <xref:System.Net.Http.HttpClient> is created from an injected <xref:System.Net.Http.IHttpClientFactory>. If you don't use an <xref:System.Net.Http.IHttpClientFactory>, you must create an <xref:System.Net.Http.HttpClientHandler> instance and assign it to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.AuthorizationMessageHandler>'s <xref:System.Net.Http.DelegatingHandler.InnerHandler%2A?displayProperty=nameWithType>:
305+
>
306+
> ```csharp
307+
> InnerHandler = new HttpClientHandler();
308+
> ```
309+
>
310+
> You don't need to make the preceding <xref:System.Net.Http.DelegatingHandler.InnerHandler> assignment if you use <xref:System.Net.Http.IHttpClientFactory>, as the `ExampleAPIMethod` call later in this section demonstrates.
311+
303312
In the preceding code, the scopes `example.read` and `example.write` are generic examples not meant to reflect valid scopes for any particular provider.
304313

305314
In the `Program` file, `CustomAuthorizationMessageHandler` is registered as a transient service and is configured as the <xref:System.Net.Http.DelegatingHandler> for outgoing <xref:System.Net.Http.HttpResponseMessage> instances made by a named <xref:System.Net.Http.HttpClient>.
@@ -378,7 +387,10 @@ builder.Services.AddScoped(sp => new HttpClient(
378387
});
379388
```
380389

381-
In the preceding code, the scopes `example.read` and `example.write` are generic examples not meant to reflect valid scopes for any particular provider.
390+
In the preceding code:
391+
392+
* The scopes `example.read` and `example.write` are generic examples not meant to reflect valid scopes for any particular provider.
393+
* <xref:System.Net.Http.IHttpClientFactory> isn't used to create <xref:System.Net.Http.HttpClient> instances, so an <xref:System.Net.Http.HttpClientHandler> instance is manually created and assigned to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.AuthorizationMessageHandler>'s <xref:System.Net.Http.DelegatingHandler.InnerHandler%2A?displayProperty=nameWithType>.
382394

383395
:::moniker range="< aspnetcore-8.0"
384396

0 commit comments

Comments
 (0)