一个 .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[] { };
}
相关推荐
白雪讲堂8 小时前
从流量到增长:庞文英《GEO实战:AI时代的增长密码》重磅上市,开启AI营销新纪元
microsoft
acrel710 小时前
浅谈碳中和背景下企业绿色低碳转型
人工智能·物联网·microsoft
岁月刘声机11 小时前
国标实施|《法律法规电子文件》三项标准正式施行,电子文档可信闭环成关键
大数据·人工智能·microsoft
把我格子衫拿来11 小时前
本周科技热点:Meta 新模型、微软 Maia 300 与 AI 智能体新动向(10.12—10.15)
人工智能·科技·microsoft
Data-Miner12 小时前
数据分析,除了Excel数据透视表,还有什么工具?——2026 专业精选推荐榜
microsoft·数据分析·excel
阿乔外贸日记12 小时前
美国买家资产包装套路与应收款尽调框架,580万应收账款案例解析
大数据·服务器·人工智能·microsoft·云计算
云表无代码开发1 天前
雷军救WPS“三次”!WPS注入新生力量,不再抄袭微软
大数据·microsoft
兰亭妙微UI设计公司1 天前
兰亭妙微交互设计公司工作流:交互设计的详细流程拆解
microsoft·交互
天空鸟_时光不老1 天前
2-1-1-章节介绍
microsoft
海盗12341 天前
微软技术日报 2026-10-15:Defender 下到 Linux 桌面,Copilot 订阅明天改名
linux·人工智能·microsoft·机器人·aigc·copilot