asp.net-core - CascadingAuthenticationState 和 NotFoundContent 标签在 Blazor 中不起作用

标签 asp.net-core nuget nuget-package blazor blazor-client-side

所以我一直在关注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/

相关文章:

c# - 无法在 vs 2017 中添加任何 nuget 包

.net - NuGet:远程服务器返回错误(403)禁止

javascript - 单击链接时更改变量

javascript - 如何复制 wwwroot 中的图片,或者如何引用它们?

c# - 将 IdentityServer4 配置为仅颁发 token

visual-studio-code - 从 VS-Code 添加 NuGet 包时出错

nuget - 如何打开 NuGet 包的自述 URL?

asp.net-mvc - jQuery Validation 和 Microsoft jQuery Unobtrusive 之间的区别

c# - 如何在 ConfigureServices 中获取 Development/Staging/production Hosting Environment

visual-studio - 如何确保 nuget 程序集是按包添加的,而不仅仅是对 DLL 文件的引用?