Код: Выделить всё
@attribute [Authorize(Policy = "PolicyName")]Код: Выделить всё
InvalidOperationException: Unable to find the required 'IAuthenticationService' service.
Please add all the required services by calling
'IServiceCollection.AddAuthentication' in the application startup code.
Не хватает ли мне какой-либо необходимой конфигурации для использования @attribute [Authorize] на Blazor Server?
Код: Выделить всё
Program.csКод: Выделить всё
var builder = WebApplication.CreateBuilder( args );
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
//builder.Services.AddAuthentication();
builder.Services.AddAuthorization( options =>
{
options.AddPolicy( "CanViewAdminDashboard", policy =>
policy.RequireRole( "Admin" ) );
} );
builder.Services.AddNavigationAuthorization();
var app = builder.Build();
// Configure the HTTP request pipeline.
if( !app.Environment.IsDevelopment() )
{
app.UseExceptionHandler( "/Error", createScopeForErrors: true );
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseStatusCodePagesWithReExecute( "/not-found", createScopeForStatusCodePages: true );
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseAntiforgery();
app.MapRazorComponents()
.AddInteractiveServerRenderMode();
app.Run();
Код: Выделить всё
Secure.razorКод: Выделить всё
@page "/secure"
@attribute [Authorize(Policy = "CanViewAdminDashboard")]
Secure Page
This page should be protected by PolicyName.
Подробнее здесь: https://stackoverflow.com/questions/798 ... vice-error
Мобильная версия