admin管理员组文章数量:1296843
I have a Blazor Web App and I'm am trying to add authentication. I can verify that my user is logged in by calling the following code on one of my unsecured pages:
private async Task CheckAuth()
{
var state = await AuthStateProvider.GetAuthenticationStateAsync();
var user = state.User;
if (user.Identity.IsAuthenticated)
{
Console.WriteLine("User is authenticated!");
}
else
{
Console.WriteLine("User is NOT authenticated.");
}
}
But, as soon as I try to visit the following page with @attribute [Authorized], to shows that my user is NOT logged in:
@using Aelios.Client.Layout
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@page "/secure/dashboard"
@attribute [Authorize]
@layout AdminLayout
<PageTitle>Dashboard</PageTitle>
INSIDE SECURE DASHBOARD
@code {
}
If I however REMOVE the attribute and try the following, it shows that the user indeed IS authenticated:
@using Aelios.Client.Layout
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@page "/secure/dashboard"
@layout AdminLayout
<PageTitle>Dashboard</PageTitle>
INSIDE SECURE DASHBOARD
<CascadingAuthenticationState>
<AuthorizeView>
<Authorized>
<p>✅ You are authorized!</p>
<p>
本文标签:
authenticationattribute Authorized not recognizing authenticated userStack Overflow
版权声明:本文标题:authentication - @attribute [Authorized] not recognizing authenticated user? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1741644253a2390093.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论