简体   繁体   English

使用 Blazor 模态和身份验证状态

[英]Using Blazor Modal and Authentication State

I'm trying to use Blazored.Modal with AuthenticationState .我正在尝试将Blazored.ModalAuthenticationState一起使用。

I can't find any documents that shows how to combine these two attributes/keys in the App.Razor file.我找不到任何说明如何在 App.Razor 文件中组合这两个属性/键的文档。

Below is how I currently have my App.Razor:以下是我目前拥有 App.Razor 的方式:

 <CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="@lazyLoadedAssemblies" OnNavigateAsync="@OnNavigateAsync">
        <Found Context="routeData">
                <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                        @if (!context.User.Identity.IsAuthenticated)
.
.
.
</CascadingAuthenticationState>

I need to insert <CascadingBlazoredModal> somewhere but I have no clue.我需要在某处插入<CascadingBlazoredModal>但我不知道。 I've tried adding it below but that seems to create two renders of the page.我试过在下面添加它,但这似乎创建了页面的两个渲染。 I tried wrapping the above code with CascadingBlazoredModal, I tried putting CascadingBlazoredModal inside the AuthenticationState.我尝试用 CascadingBlazoredModal 包装上面的代码,我尝试将 CascadingBlazoredModal 放在 AuthenticationState 中。

The only docs I see are around CascadingValues/Params but that's not what I'm looking for.我看到的唯一文档是关于 CascadingValues/Params 的,但这不是我要找的。

Any help would be appreciate it!任何帮助将不胜感激!

Thank you!谢谢!

I've not tested this, but from the docs this should work:我没有测试过这个,但是从文档来看这应该有效:

<CascadingAuthenticationState>
  <CascadingBlazoredModal>
    <Router AppAssembly="typeof(Program).Assembly">
        ...
    </Router>
 </CascadingBlazoredModal>
</CascadingAuthenticationState>

You should be able to pick up the cascaded value in your modal hosted forms.您应该能够在模态托管表单中获取级联值。

[CascadingParameter] public Task<AuthenticationState> AuthTask { get; set; }

I got it to work!我让它工作! Not sure if it's the best option but...不确定这是否是最好的选择,但是......

I had to wrap the CascadingBlazoredModal around the Authenticationstate ... AND add authenticationstate within the Found ...我不得不将CascadingBlazoredModal包裹在Authenticationstate周围……并在Found添加 authenticationstate ...

If I don't wrap the whole Router with the AuthenticationState I wouldn't be able to access the whole app but just the page I authenticated myself with (sigh)..如果我不使用AuthenticationState包装整个Router ,我将无法访问整个应用程序,而只能访问我使用(叹气)对自己进行身份验证的页面。

<CascadingBlazoredModal> 
    <CascadingAuthenticationState>
        <Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="@lazyLoadedAssemblies" OnNavigateAsync="@OnNavigateAsync">
            <Found Context="routeData">
                <CascadingAuthenticationState>
                    <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
                </CascadingAuthenticationState>
            </Found>
.
.
.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Blazor State 使用 Fluxor: ActionSubscriber 或 SubscribeToAction 哪个更好用? - Blazor State with using Fluxor: ActionSubscriber or SubscribeToAction what is better to use? .net Blazor 认证机制 - .net Blazor authentication mechanism Blazor 服务器身份验证 - Blazor server authentication 具有共享 UI 库和身份验证的 .NET MAUI Blazor - .NET MAUI Blazor with a shared UI library and authentication 使用 Blazor 服务器推送通知 - push notifications using Blazor Server Blazor 发布后客户端/服务器 AAD 身份验证问题 - Blazor Client/Server AAD Authentication issue after publish Blazor Server.Net Core Authentication 链接到其他数据库表 - Blazor Server .Net Core Authentication linking to other database tables .NET Core 3.1 Web API 和 Blazor 服务器端 JWT 身份验证 - .NET Core 3.1 Web API and Blazor Server Side JWT Authentication 通过依赖注入使用 Blazor Webassembly 进行 gRPC-Web 通道身份验证 - gRPC-Web Channel Authentication with Blazor Webassembly via Dependency Injection 在 Blazor 中,有没有办法在不更改 state 的情况下撤消无效的用户输入? - In Blazor, is there a way to undo invalid user input, without changing the state?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM