一个 .net 8 + Azure 登录 + Ant Design Blazor 的基本后台框架

一个 .net 8 + Azure 登录 + Ant Design Blazor 的基本后台框架

主界面使用了 Ant Design Blazor 项目模板搭建

后台技术是 .net 8 Blazor run at server 模式

登录方式使用 Azure

实现了菜单导航和路由

此外实现了读取和修改本地Json文件的功能,不是必须的,不需要的可以拿掉,我是自己项目需要

点击下载

由于没有对权限进行细分,所以没有做菜单的权限控制,基本上有 Azure 账户就能登录进来,如果要细分,也很简单,就是在 Azure 的 Claims 里做文章,这里也不说了

Azure 登录的关键代码在 BasicLayout.razor,这点跟传统的登录以后再跳转有些不一样

cs 复制代码
@namespace Bestrane.OPS.Web
@inherits LayoutComponentBase
@inject NavigationManager _navigationManager
<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <AuthorizeView>
                <Authorized>
                    <AntDesign.ProLayout.BasicLayout Logo="@("https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg")"
                                                     MenuData="_menuData">
                        <RightContentRender>
                            <Bestrane.OPS.Web.Components.RightContent />
                        </RightContentRender>
                        <ChildContent>
                            @Body
                        </ChildContent>
                        <FooterRender>
                            <FooterView Copyright="2024 BOPS" Links="Links"></FooterView>
                        </FooterRender>
                    </AntDesign.ProLayout.BasicLayout>
                    <SettingDrawer />
                </Authorized>
                <NotAuthorized>
                    <div class="main__b__0">
                        <div class="login">
                            <Card Title="BOPS" Style="width:300px;">
                                <Body>
                                    <Button Type="@ButtonType.Primary" OnClick="HandleSubmit">
                                        Azure Login
                                    </Button>
                                </Body>
                            </Card>
                        </div>
                    </div>
                    @* <li><a href="MicrosoftIdentity/Account/SignIn">Log in</a></li> *@
                </NotAuthorized>
            </AuthorizeView>
        </Found>
    </Router>
    <AntContainer />
</CascadingAuthenticationState>

@code
{
    public void HandleSubmit()
    {
        _navigationManager.NavigateTo("MicrosoftIdentity/Account/SignIn", true);
    }

    private MenuDataItem[] _menuData = { };

    [Inject] public HttpClient? _httpClient { get; set; }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        _menuData = await _httpClient.GetFromJsonAsync<MenuDataItem[]>("data/menu.json");
    }

    public LinkItem[] Links { get; set; } = new LinkItem[] { };
}
相关推荐
J.T.L16 小时前
Windows 10/11 本地/微软账户密码遗忘:终极自救
windows·microsoft
宝桥南山18 小时前
GitHub Copilot - 尝试配置和使用一下Microsoft Fabric Core MCP Server
运维·microsoft·ai·微软·powerbi·fabric
海盗123420 小时前
微软技术日报·2026-08-28——微软正式将 Microsoft 365 Roadmap 重命名为 **AI at Work
人工智能·microsoft
学习星球1 天前
2026 AI游戏开发实战指南:从NVIDIA ACE到Summer Engine,AI如何重塑游戏开发
人工智能·microsoft
cd_949217212 天前
具身大脑成机器人产业核心底座,星源智技术落地与产业布局解析
人工智能·microsoft·机器人
编码者卢布2 天前
【Azure Developer】通过 API 获取 Azure VM 信息实践指南 Part 2(Azure China)
python·flask·azure
星云API|微信接口开发2 天前
企业微信二次开发:企业微信外部群机器人怎么做?从群消息接收到事件处理
microsoft·机器人·企业微信
Wang's Blog3 天前
Vibe Coding一人即团队系列11: 提示词三大核心角色 (System, User, Assistant) 详解与应用实战
microsoft
曹牧3 天前
C#与Java后台交互
java·windows·microsoft·c#
HwJack203 天前
鸿蒙 Accessibility Kit 全景解析:无障碍开发从哪里下手
microsoft·华为·harmonyos