我们开始将项目迁移到blazor,并且在将内容限制为仅已登录的用户方面存在一些问题。
对于此测试,我们使用了标准的Visual Studio 2019 Blazor服务器端项目模板,其中启用了本地用户和帐户身份验证。
然后我们将App.razor文件更改为以下内容:
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Mainlayout)">
<NotAuthorized>
NOT AUTHORIZED!!!!!
</NotAuthorized>
<Authorizing>
AUTHORIZING!!!!!
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(Mainlayout)">
<p>Sorry,there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
<NotAuthorized>
中的代码永远不会被击中,我已经确认浏览器上没有cookie,甚至还尝试在专用浏览器窗口中尝试
我在另一个组件中注入了HTTPContext,以查看当前用户的情况。当前用户不为null,具有身份,但显示未经身份验证,并且没有预期的声明。
我这里缺少什么吗?