Closed zuijiaoghb closed 2 days ago
Sorry, but this is not an issue report we can work with.
Please provide us with a zip file or repository for the code and at least make the screenshot in a language that we can read.
Closing this one so you can create a new one.
🐛 Bug Report
Blazor uses a fallback authorization strategy, and the component is not rendered normally.
💻 Repro or Code Sample
[root@cpzljc jtpjsapp]# cat Program.cs using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.FluentUI.AspNetCore.Components; using jtpjsapp.Components; using jtpjsapp.Components.Account; using jtpjsapp.Data; using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using Microsoft.AspNetCore.Authorization; using jtpjsapp.Authorization;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddFluentUIComponents(); builder.Services.AddDataGridEntityFrameworkAdapter();
builder.Services.AddCascadingAuthenticationState(); builder.Services.AddScoped();
builder.Services.AddScoped();
builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>();
builder.Services.AddAuthentication(options => { options.DefaultScheme = IdentityConstants.ApplicationScheme; options.DefaultSignInScheme = IdentityConstants.ExternalScheme; }) .AddIdentityCookies();
//var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); //builder.Services.AddDbContext(options =>
// options.UseSqlite(connectionString));
builder.Services.AddDbContextFactory(opt =>
opt.UseMySql("server=;port=;database=;user=;password=" , new MySqlServerVersion(new Version(8, 0, 31)) )
// The following three options help with debugging, but should
// be changed or removed for production.
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging()
.EnableDetailedErrors() );
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddIdentityCore(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles()
.AddEntityFrameworkStores()
.AddSignInManager()
.AddDefaultTokenProviders();
builder.Services.AddRazorPages();
builder.Services.AddAuthorization(options => { options.FallbackPolicy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); });
builder.Services.AddSingleton<IEmailSender, IdentityNoOpEmailSender>();
// Authorization handlers. builder.Services.AddScoped<IAuthorizationHandler, RecbillIsOwnerAuthorizationHandler>();
builder.Services.AddSingleton<IAuthorizationHandler, RecbillAdministratorsAuthorizationHandler>();
builder.Services.AddSingleton<IAuthorizationHandler, RecbillManagerAuthorizationHandler>();
var app = builder.Build();
using (var scope = app.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService();
context.Database.Migrate();
// requires using Microsoft.Extensions.Configuration;
// Set password with the Secret Manager tool.
// dotnet user-secrets set SeedUserPW
await SeedData.Initialize(services, testUserPw); }
// Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseMigrationsEndPoint(); } else { 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.UseHttpsRedirection();
//app.UseRouting(); app.UseAuthentication(); app.UseAuthorization();
app.UseStaticFiles(); app.UseAntiforgery();
app.MapRazorComponents()
.AddInteractiveServerRenderMode();
// Add additional endpoints required by the Identity /Account Razor components. app.MapAdditionalIdentityEndpoints();
app.Run();
[root@cpzljc Pages]# cat Login.razor @page "/Account/Login" @attribute [AllowAnonymous]
@using System.ComponentModel.DataAnnotations @using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Identity @using jtpjsapp.Data
@inject SignInManager SignInManager
@inject ILogger Logger
@inject NavigationManager NavigationManager
@inject IdentityRedirectManager RedirectManager
登录
使用注册后的邮箱登录。
Use another service to log in.