所以我一直在关注this tutorial用于在我的 blazor 客户端应用程序(托管的 asp.net 核心)上实现授权/身份验证。一切正常,直到我开始在客户端工作(the tutorial 中的“配置客户端 Blazor”副标题)。我已经成功安装了 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
我该如何解决这个问题?看起来这些组件应该默认可用。即使没有,我也无法在互联网上找到这些组件的 namespace 。
最佳答案
您需要从 NuGet 安装 Microsoft.AspNetCore.Components.Authorization
包。在我写那篇文章时,这个包还不存在。安装它并向 _Imports.razor
添加 using 后,您就可以开始使用了。
关于asp.net-core - CascadingAuthenticationState 和 NotFoundContent 标签在 Blazor 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58465964/