2

所以我一直在按照本教程在我的 blazor 客户端应用程序(托管 asp.net 核心)上实现授权/身份验证。一切正常,直到我开始在客户端工作(教程中的“配置客户端 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 包):3.0.0-preview9.19465.2

ASP.NET Core(Microsoft.AspNetCore.Blazor.Server nuget 包):3.0.0-preview9.19465.2

共享:.NET Standard 2.0 库

我该如何解决这个问题?看起来这些组件应该默认可用。即使没有,我也无法在互联网上找到这些组件的名称空间。

4

1 回答 1

8

您需要Microsoft.AspNetCore.Components.Authorization从 NuGet 安装包。在我写那篇文章的时候,这个包还不存在。一旦你安装了它并添加了一个使用,_Imports.razor你应该很高兴。

于 2019-10-19T17:28:15.557 回答