
Block
Depending on the parameter conditions, the contents of the block are determined to be displayed, usually in conjunction with permission authorization
Determines whether component content is displayed by setting the OnQueryCondition
callback method return value
Demo
By setting authorized
NotAuthorized
you can set what appears when you meet and do not meet the criteria, respectively
Demo
This example simulates a user logging in to control whether the content Block
is displayed, which is easier to use than AuthorizeView
Demo
AuthorizeView
component and are not currently logged inBy setting Users
controls the display, which is displayed when the currently logged-in user is a preset user
Demo
By setting Roles
controls the display, which is displayed when the currently logged-in user is in a preset role
Demo
Attributes
@page "/blocks"
@inject IStringLocalizer<Blocks> Localizer
<h3>Block</h3>
<h4>Depending on the parameter conditions, the contents of the block are determined to be displayed, usually in conjunction with permission authorization</h4>
<DemoBlock Title="Common usage" Introduction="Determines whether component content is displayed by setting the <code>OnQueryCondition</code> callback method return value" Name="Normal" Demo="typeof(Demos.Block.BlockNormal)" />
<DemoBlock Title="Template" Introduction="By setting <code>authorized</code> <code>NotAuthorized</code> you can set what appears when you meet and do not meet the criteria, respectively" Name="Template" Demo="typeof(Demos.Block.BlockTemplate)" />
<DemoBlock Title="Judging by permissions" Introduction="This example simulates a user logging in to control whether the content <code>Block</code> is displayed, which is easier to use than <code>AuthorizeView</code>" Name="Authorizate" Demo="typeof(Demos.Block.BlockAuthorizate)" />
<DemoBlock Title="Pre-set the user" Introduction="By setting <code>Users</code> controls the display, which is displayed when the currently logged-in user is a preset user" Name="Users" Demo="typeof(Demos.Block.BlockUsers)" />
<DemoBlock Title="Preset roles" Introduction="By setting <code>Roles</code> controls the display, which is displayed when the currently logged-in user is in a preset role" Name="Roles" Demo="typeof(Demos.Block.BlockRoles)" />
<Tips class="mt-3">
<p>By setting different <code>Name</code> as a resource, combined with the authorization system to authorize this resource can be achieved to any element of the Web page permission control</p>
</Tips>
<AttributeTable Items="@GetAttributes()" />
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using BootstrapBlazor.Shared.Services;
using Microsoft.AspNetCore.Components.Authorization;
namespace BootstrapBlazor.Shared.Samples;
/// <summary>
///
/// </summary>
public partial class Blocks
{
private IEnumerable<AttributeItem> GetAttributes() => new AttributeItem[]
{
new AttributeItem()
{
Name = nameof(Block.OnQueryCondition),
Description = Localizer["OnQueryCondition"],
Type = "Func<Task<bool>>",
ValueList = " — ",
DefaultValue = "true"
},
new AttributeItem()
{
Name = nameof(Block.ChildContent),
Description = Localizer["ChildContent"],
Type = "RenderFragment",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = nameof(Block.Authorized),
Description = Localizer["Authorized"],
Type = "RenderFragment",
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem()
{
Name = nameof(Block.NotAuthorized),
Description = Localizer["NotAuthorized"],
Type = "RenderFragment",
ValueList = " — ",
DefaultValue = " — "
}
};
}