Skip to content

Commit a72cd19

Browse files
authored
[Blazor] Security overview - SecureMethod correction (#34031)
1 parent 1b4668e commit a72cd19

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

aspnetcore/blazor/security/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,19 @@ You can also supply different content for display if the user isn't authorized w
439439
<AuthorizeView>
440440
<Authorized>
441441
<p>Hello, @context.User.Identity?.Name!</p>
442-
<p><button @onclick="SecureMethod">Authorized Only Button</button></p>
442+
<p><button @onclick="HandleClick">Authorized Only Button</button></p>
443443
</Authorized>
444444
<NotAuthorized>
445445
<p>You're not authorized.</p>
446446
</NotAuthorized>
447447
</AuthorizeView>
448448
449449
@code {
450-
private void SecureMethod() { ... }
450+
private void HandleClick() { ... }
451451
}
452452
```
453453

454-
A default event handler for an authorized element, such as the `SecureMethod` method for the `<button>` element in the preceding example, can only be invoked by an authorized user.
454+
Although the <xref:Microsoft.AspNetCore.Components.Authorization.AuthorizeView> component controls the visibility of elements based on the user’s authorization status, it doesn't enforce security on the event handler itself. In the preceding example, the `HandleClick` method is only associated with a button visible to authorized users, but nothing prevents invoking this method from other places. To ensure method-level security, implement additional authorization logic within the handler itself or in the relevant API.
455455

456456
:::moniker range=">= aspnetcore-8.0"
457457

0 commit comments

Comments
 (0)