- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们开始将一个项目迁移到 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,甚至在私有(private)浏览器窗口中也尝试过。
我在另一个组件中注入(inject)了 HTTPContext 以查看当前用户发生了什么。当前用户不为空,它有一个身份,但显示为未经身份验证,并且没有预期的声明。
我在这里遗漏了什么吗?
最佳答案
我在 WebAssembly(客户端)项目中对当前 Blazor 版本有同样的问题。
如果 Blazor 团队能告诉我们我们做错了什么,那就太好了,因为您使用的代码正是他们建议使用的代码。
我通过使用 <AuthorizeView>
找到了解决方法在我的主布局中。有<NotAuthorized>
部分执行正确,您可以使用他们建议的代码to force a redirect to log on :
<AuthorizeView>
<Authorized>
<!-- Markup of your MainLayout -->
</Authorized>
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeView>
关于asp.net-core - AuthorizeRouteView 不适用于已注销的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58789545/
我们开始将一个项目迁移到 blazor,但在将内容限制为仅登录用户时遇到了一些问题。 对于此测试,我们使用了标准的 Visual Studio 2019 Blazor 服务器端项目模板,并启用了本地用
我想使用 NotAuthorized 中的属性每次非登录用户尝试访问页面时重定向到登录页面的标记。 然而,它需要一个 RenderFragment类型参数。我应该设置什么来设置这个参数来呈现登录页面
我不明白为什么我总是收到这个异常(exception)。我尝试保护 Blazor WebAssembly blazor.webassembly.js:1 WASM: System.MissingMet
我是一名优秀的程序员,十分优秀!