一个 .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[] { };
}
相关推荐
V搜xhliang02464 小时前
临床科研新范式:从选题到投稿,AI智能体如何接管全流程?
运维·数据结构·人工智能·算法·microsoft·数据挖掘·自动化
爱看科技5 小时前
微软Majorana 2量子芯片横空出世,IBM与WiMi微美全息双线并进加速量子+AI商用落地
人工智能·microsoft·量子计算
初圣魔门首席弟子7 小时前
Qt Platform Plugin错误分析与解决报告
microsoft
尽兴-8 小时前
1.3 交互基础:Prompt、Context、Memory、思维链 CoT
microsoft·prompt·交互·memory·思维链 cot
360智汇云8 小时前
Data Agent 技术介绍(上)
microsoft
1892280486112 小时前
NV041固态MT29F16T08GSLCEM9-QBES:C
人工智能·算法·microsoft·缓存·性能优化
编码者卢布12 小时前
【Azure App Service】应用服务中的SNAT (Source Network Address Translation 源网络地址转化)
microsoft·azure
跨境牛马哥13 小时前
2026 Claude Code爬虫指南:如何搭建AI自动化数据采集系统?
microsoft
fuquxiaoguang14 小时前
系统软件“不破不立”:微软Project Solara与智能体优先的范式革命
microsoft·project solara·智能体优先
ID_1800790547315 小时前
TikTok 视频详情 & 列表 API 接口技术文档(带全套 JSON 样例・核心章节)
linux·windows·microsoft