[英]Using Blazor Modal and Authentication State
I'm trying to use Blazored.Modal with AuthenticationState .我正在尝试将Blazored.Modal与AuthenticationState一起使用。
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.