如何显示用户身份验证的,但在Blazor的NAV菜单中未授权
我正在开发新兴的新应用程序。我有ASP.NET身份设置和工作。
有没有办法进行身份验证,但没有授权?
例如,最初我们要求用户注册,但直到我们手动添加它们之前,我们才添加其角色。
因此,可以通过输入正确的用户名和密码来验证用户,但没有角色,因此不会有菜单项。
有没有办法在用ASP.NET身份的Blazor Razor中进行此操作?
<AuthorizeView Roles="@X.Shared.Constants.AspNetRolesConstants.Administrator.ToString()">
<Authorized>
<h3>Welcome to X Research!</h3>
</Authorized>
<NotAuthorized>
<h3>Welcome to X Research!</h3>
<br />
Please Log in!
<br /><br />
(If you are returned to this page, please contact an Administrator to have roles added for your account!)
</NotAuthorized>
</AuthorizeView>
我读了这但这似乎并没有做我想做的事情。
谢谢。
更新
当我使用上述授权>
等。然后,当您未登录时,我会看到:
”主索引上的“未授权”。RAZOR页面如果需要登录。
也许有一种方法可以重定向到我的登录页面,如果它们未获得授权?
I'm working on a new application in Blazor. I have asp.net identity setup and working.
Is there a way to be authenticated, but not authorized?
For example, initially we are requiring users to register, but are not adding their roles until we manually add them.
So the user could be authenticated by entering the correct user name and password, but has no roles, so there would be no menu items.
Is there a way to do this in Blazor razor with asp.net identity?
<AuthorizeView Roles="@X.Shared.Constants.AspNetRolesConstants.Administrator.ToString()">
<Authorized>
<h3>Welcome to X Research!</h3>
</Authorized>
<NotAuthorized>
<h3>Welcome to X Research!</h3>
<br />
Please Log in!
<br /><br />
(If you are returned to this page, please contact an Administrator to have roles added for your account!)
</NotAuthorized>
</AuthorizeView>
I read this article, but it doesn't seem to do what I want to do.
Thanks.
Update
When I use the above AuthorizeView
etc., then when you are not logged in, I see this:
So I would rather not show 'Not Authorized' on the main Index.razor page if they need to log in.
Maybe there is a way to redirect to my Login page if they are not authenicated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以重定向到其他页面,只是注入NavigationManager:
Yes you can redirect to other Pages just inject the NavigationManager:
@david让我做正确的答案:
钥匙是添加
@Attribute [allyAnymous]
,因此它允许经过身份验证的构建。如果我不说,它将说“未授权”这是我的完整代码:
@David let me do the correct answer:
The key was adding
@attribute [AllowAnonymous]
so it allows past the build in authentication. If I do not put this, it will say 'Not Authorized'Here is my full code: