一个 .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[] { };
}
相关推荐
编码者卢布6 分钟前
【Azure APIM】API导入功能报错 Unable to parse specified file.
microsoft·azure
發糞塗牆2 小时前
【Azure 架构师学习笔记 】- Azure AI(23) -AI知识库Agent平台(2)-文档向量化与向量库存储
人工智能·ai·azure
齐齐大魔王2 小时前
linux-系统函数
linux·运维·microsoft
發糞塗牆2 小时前
【Azure 架构师学习笔记 】- Azure AI(22) -AI知识库Agent平台(1)- 项目启动及基础搭建
人工智能·ai·azure
智算菩萨3 小时前
【Tkinter】3 Tkinter Button 控件深度解析:从事件绑定到现代交互设计实战
python·microsoft·ui·交互·tkinter·button
七夜zippoe16 小时前
OpenClaw 接入 WhatsApp:消息推送实战
大数据·人工智能·microsoft·whatsapp·openclaw
我不是懒洋洋18 小时前
预处理详解
c语言·开发语言·c++·windows·microsoft·青少年编程·visual studio
武藤一雄19 小时前
C#:nameof 运算符全指南
开发语言·microsoft·c#·.net·.netcore
七夜zippoe20 小时前
OpenClaw 接入 Telegram:BotFather 实战
microsoft·ngrok·telegram·openclaw·botfather
小妖同学学AI21 小时前
微软开源多智能体协作框架AutoGen:像组建公司一样,打造会“开会”的AI团队
人工智能·microsoft·开源