You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/security/server/index.md
+4-50Lines changed: 4 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -282,9 +282,9 @@ Specify the issuer explicitly when deploying to Azure App Service on Linux with
282
282
283
283
## Inject `AuthenticationStateProvider` for services scoped to a component
284
284
285
-
Don't attempt to resolve <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> within a custom scope because it results in the creation of a new instance of the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> that isn't correctly initialized.
285
+
Don't attempt to resolve <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> within a service that's scoped to a component by [`OwningComponentBase`](xref:fundamentals/dependency-injection#owningcomponentbase) because it results in the creation of a new instance of the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> that isn't correctly initialized.
286
286
287
-
To access the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> within a service scoped to a component, inject the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> with the [`@inject` directive](xref:mvc/views/razor#inject) or the [`[Inject]` attribute](xref:Microsoft.AspNetCore.Components.InjectAttribute) and pass it to the service as a parameter. This approach ensures that the correct, initialized instance of the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> is used for each user app instance.
287
+
To access the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> within a service scoped to a component, inject the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> with the [`@inject` directive](xref:mvc/views/razor#inject) or the [`[Inject]` attribute](xref:Microsoft.AspNetCore.Components.InjectAttribute)into the component and pass the service instance to the scoped service as a parameter. This approach ensures that the correct, initialized instance of the <xref:Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider> is used for each user app instance.
288
288
289
289
`ExampleService.cs`:
290
290
@@ -308,28 +308,12 @@ public class ExampleService
308
308
}
309
309
```
310
310
311
-
Register the service as scoped. In a server-side Blazor app, scoped services have a lifetime equal to the duration of the client connection [circuit](xref:blazor/hosting-models#blazor-server).
312
-
313
-
:::moniker range=">= aspnetcore-6.0"
314
-
315
-
In the `Program` file:
311
+
In the `Program` file, the `ExampleService` is registered as a scoped service. In a server-side Blazor app, scoped services have a lifetime equal to the duration of the client connection [circuit](xref:blazor/hosting-models#blazor-server).
316
312
317
313
```csharp
318
-
builder.Services.AddScoped<ExampleService>();
314
+
.AddScoped<ExampleService>();
319
315
```
320
316
321
-
:::moniker-end
322
-
323
-
:::moniker range="< aspnetcore-6.0"
324
-
325
-
In `Startup.ConfigureServices` of `Startup.cs`:
326
-
327
-
```csharp
328
-
services.AddScoped<ExampleService>();
329
-
```
330
-
331
-
:::moniker-end
332
-
333
317
In the following `InjectAuthStateProvider` component:
334
318
335
319
* The component inherits <xref:Microsoft.AspNetCore.Components.OwningComponentBase>.
@@ -338,8 +322,6 @@ In the following `InjectAuthStateProvider` component:
338
322
339
323
`InjectAuthStateProvider.razor`:
340
324
341
-
:::moniker range=">= aspnetcore-8.0"
342
-
343
325
```razor
344
326
@page "/inject-auth-state-provider"
345
327
@inherits OwningComponentBase
@@ -362,34 +344,6 @@ In the following `InjectAuthStateProvider` component:
For more information, see the guidance on <xref:Microsoft.AspNetCore.Components.OwningComponentBase> in <xref:blazor/fundamentals/dependency-injection#owningcomponentbase>.
394
348
395
349
## Unauthorized content display while prerendering with a custom `AuthenticationStateProvider`
0 commit comments