如果未经认证的用户
我正在尝试定义一个完全导航的大风网站,以呈现非认证用户的应用程序,并为身份验证的用户提供另一个完全不同的导航。
这个想法是,未经认可的用户可以使用完整的页面和导航的匿名用户进入网站的一部分。一旦登录,他们就可以进入网站的另一部分,该部分仅适用于具有自己导航的经过身份验证的用户。
此外,我可能会根据用户的角色有两组不同的导航。
例如,管理员可能具有其他视图和菜单,而不是标准用户。
我已经查看了路由和导航文档,但找不到任何可以让我根据用户的身份验证状态或角色重定向到具有自己的Mainlayout的其他子路线的任何东西。
I'm trying to define a Blazor website that has complete navigation to present the application for non-authenticated users and another completely different navigation for authenticated users.
The idea is that non-authenticated users get to a part of the website that allows anonymous users, with a complete set of pages and navigation. Once they log in, they get to another part of the website which is only for authenticated users with its own navigation.
In addition, I might have two different sets of navigation based on the roles of the users.
For example, an admin might have other views and menus than a standard user.
I have looked at the Routing and navigation documentation, but can't find anything that would allow me to redirect the user based on its authentication state or role to another sub-route with its own MainLayout, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
app.razor:
navmenu.razor
别忘了添加启动或编程文件这两行。
Microsoft doc
App.razor:
NavMenu.razor
Don't forget to add in Startup or program file this two lines.
Microsoft doc
查看此代码:
不要忘记将其添加到您的启动文件中:
services.addhttpcontextaccessor();
这将确保可以注入IHTTPContextAccessor。
NaviationManager无需手动注入。
Take a look at this code:
Don't forget to add this to your startup file:
services.AddHttpContextAccessor();
That will make sure IHttpContextAccessor can be injected.
NaviationManager does not need to be manually injected.