我正在使用Blazor Web Server和Blazorise 0.9.5.2构建一个新的.NET 6.0应用程序。
按照目前的配置,sider布局仅对登录用户可见。匿名用户可以看到整个布局,除了sider。比较两种条件下的HTTP内容表明,匿名用户和登录用户之间的唯一区别是存在或不存在取决于授权的两个导航栏链接;欢迎,用户"与";登录";在右上角。Chrome在任何一种情况下都没有显示下载CSS或JS的失败。
MainLayout.razor看起来像这样:
<Layout Sider="true">
<LayoutSider>
<LayoutSiderContent>
<Bar Breakpoint="Breakpoint.Desktop" NavigationBreakpoint="Breakpoint.Tablet" ThemeContrast="ThemeContrast.Dark"
Mode="BarMode.VerticalInline" CollapseMode="BarCollapseMode.Small">
<BarToggler />
<BarBrand>
<BarItem>
<BarLink To="">
<BarIcon IconName="_customIcon" />
My SIte
</BarLink>
</BarItem>
</BarBrand>
<NavMenu />
</Bar>
</LayoutSiderContent>
</LayoutSider>
<Layout>
<LayoutHeader Fixed="true">
<Bar @bind-Visible="@_topbarVisible" Breakpoint="Breakpoint.Desktop" Background="Background.Primary" ThemeContrast="ThemeContrast.Light">
<BarBrand>
<BarItem>
<BarLink To="">
<BarIcon IconName="FontAwesomeIcons.CloudSun" />
My Site
</BarLink>
</BarItem>
</BarBrand>
@* ReSharper disable once UnknownCssClass *@
<BarMenu Class="justify-content-end">
<BarEnd>
<AuthorizeView>
<Authorized>
<BarItem>
<Blazorise.Icon Name="FontAwesomeIcons.User" Visibility="Visibility.Visible" />
Hi, @context?.User?.Identity?.Name
</BarItem>
</Authorized>
</AuthorizeView>
<BarItem>
<LoginDisplay />
</BarItem>
</BarEnd>
</BarMenu>
</Bar>
</LayoutHeader>
<LayoutContent Padding="Padding.Is4.OnX">
@Body
</LayoutContent>
<LayoutFooter Fixed="true" Padding="Padding.Is4.OnX">
Copyright ©@DateTimeOffset.UtcNow.Year Inner Drive Technology.
</LayoutFooter>
</Layout>
</Layout>
NavMenu.razor组件如下所示:
@using Blazorise.Icons.FontAwesome
<BarMenu>
<BarStart>
<BarItem>
<BarLink To="">
<BarIcon IconName="FontAwesomeIcons.Home" />
Home
</BarLink>
</BarItem>
<BarItem>
<BarLink To="/Current">
<BarIcon IconName="FontAwesomeIcons.CloudSun" />
Current
</BarLink>
</BarItem>
<AuthorizeView>
<Authorized>
<BarItem>
<BarLink To="/ApiStatus">
<BarIcon IconName="FontAwesomeIcons.Server" />
API Status
</BarLink>
</BarItem>
<BarItem>
<BarLink To="/BuildStatus">
<BarIcon IconName="FontAwesomeIcons.Rocket" />
Build Status
</BarLink>
</BarItem>
</Authorized>
</AuthorizeView>
<BarItem>
<BarLink To="/About">
<BarIcon IconName="FontAwesomeIcons.InfoCircle" />
About
</BarLink>
</BarItem>
</BarStart>
</BarMenu>
Program.cs包含以下部分:
builder.Services.AddRazorPages(options =>
{
options.Conventions.AllowAnonymousToFolder("/");
options.Conventions.AllowAnonymousToPage("/Index");
options.Conventions.AllowAnonymousToFolder("/_content");
options.Conventions.AllowAnonymousToFolder("/Pages");
options.Conventions.AllowAnonymousToFolder("/Shared");
});
问题似乎是Mode="0"的存在;BarMode.VverticalInline";属性(我将省去导致这一结论的A/B测试。(当Mode属性存在时,整个sider对匿名用户都是隐藏的。当它不存在时,整个恒星都是可见的。
有人知道这是怎么回事吗?
这很有趣。所有CORS的东西都是转移注意力。
问题是:默认的AddAuthorization服务提供程序选项在某个地方阻止了请求,因此删除它可以加载所有页面组件,即使隐藏了身份验证所需的位。
builder.Services.AddAuthorization(options =>
{
// By default, all incoming requests will be authorized according to the default policy
//options.FallbackPolicy = options.DefaultPolicy; // Removed this line
});
删除回退策略修复了此问题。