Я также удалил некоторые настройки для упрощения кода< /p>
Код: Выделить всё
builder.Services.
AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);
Код: Выделить всё
@attribute [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
@context.User.Identity.IsAuthenticated
[CascadingParameter] Task AuthenticationState { get; set; }
protected override async Task OnInitializedAsync()
{
if (AuthenticationState is not null)
{
var authResult= await AuthenticationState;
authResult.User.Identity.IsAuthenticated //is false
}
}
но если я изменил конфигурацию аутентификации следующим образом, все работает нормально
Код: Выделить всё
builder.Services.
AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);
Подробнее здесь: https://stackoverflow.com/questions/793 ... ion-scheme
Мобильная версия