CascadingAuthenticationState 和 NotFoundContent 标签在 Blazor 中不起作用
CascadingAuthenticationState and NotFoundContent tags not working in Blazor
所以我一直在关注 this tutorial for implementing authorization/authentication on my blazor client app (asp.net core hosted). Everything worked ok until I started working on client side ("Configuring client-side Blazor" subtitle in the tutorial)。我已经成功安装 Blazored.LocalStorage nuget 包。但是我未能将 "CascadingAuthenticationState" 和 "NotFoundContent" 组件添加到我的 App.razor 文件中。编译器看不到这些组件,要求添加using指令。
这是_Imports.razor:
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using Musical_WebStore_BlazorApp.Client
@using Musical_WebStore_BlazorApp.Client.Shared
@using Microsoft.AspNetCore.Authorization
@using Blazored.LocalStorage
这是无法正常工作的 App.razor(我请求帮助我让它正常工作):
<CascadingAuthenticationState>
<Router AppAssembly="typeof(Program).Assembly">
<NotFoundContent>
<p>Sorry, there's nothing at this address.</p>
</NotFoundContent>
</Router>
</CascadingAuthenticationState>
这是正在工作的 App.razor(默认情况下我有):
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
以下是项目的版本:
Blazor.Client (Microsoft.AspNetCore.Blazor nuget package): 3.0.0-preview9.19465.2
ASP.NET Core (Microsoft.AspNetCore.Blazor.Server nuget package): 3.0.0-preview9.19465.2
Shared: .NET Standard 2.0 library
如何解决这个问题?看起来这些组件应该默认可用。即使没有,我也无法在互联网上找到这些组件的命名空间。
您需要从 NuGet 安装 Microsoft.AspNetCore.Components.Authorization
包。在我写那篇文章时,这个包还不存在。一旦你安装了它并添加了一个 using 到 _Imports.razor
你应该可以开始了。
所以我一直在关注 this tutorial for implementing authorization/authentication on my blazor client app (asp.net core hosted). Everything worked ok until I started working on client side ("Configuring client-side Blazor" subtitle in the tutorial)。我已经成功安装 Blazored.LocalStorage nuget 包。但是我未能将 "CascadingAuthenticationState" 和 "NotFoundContent" 组件添加到我的 App.razor 文件中。编译器看不到这些组件,要求添加using指令。
这是_Imports.razor:
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using Musical_WebStore_BlazorApp.Client
@using Musical_WebStore_BlazorApp.Client.Shared
@using Microsoft.AspNetCore.Authorization
@using Blazored.LocalStorage
这是无法正常工作的 App.razor(我请求帮助我让它正常工作):
<CascadingAuthenticationState>
<Router AppAssembly="typeof(Program).Assembly">
<NotFoundContent>
<p>Sorry, there's nothing at this address.</p>
</NotFoundContent>
</Router>
</CascadingAuthenticationState>
这是正在工作的 App.razor(默认情况下我有):
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
以下是项目的版本:
Blazor.Client (Microsoft.AspNetCore.Blazor nuget package): 3.0.0-preview9.19465.2
ASP.NET Core (Microsoft.AspNetCore.Blazor.Server nuget package): 3.0.0-preview9.19465.2
Shared: .NET Standard 2.0 library
如何解决这个问题?看起来这些组件应该默认可用。即使没有,我也无法在互联网上找到这些组件的命名空间。
您需要从 NuGet 安装 Microsoft.AspNetCore.Components.Authorization
包。在我写那篇文章时,这个包还不存在。一旦你安装了它并添加了一个 using 到 _Imports.razor
你应该可以开始了。