Azure B2C与Blazor Web App集成技术指导求助
Azure B2C 与 Blazor Web App 集成问题
问题描述
我们正尝试将Azure B2C与Blazor Web App集成,虽有官方通用指导文档但仍未找到解决方案。通过Visual Studio创建Blazor Server App时集成该功能很简单,但新版Blazor Web App仅提供个人登录选项。
我们已尝试遵循官方文档指导但无效,运行时出现错误:An action cannot use both form and JSON body parameters.
当前program.cs代码如下:
using AzureB2CTesting2.Components; using AzureB2CTesting2.Components.Account; using AzureB2CTesting2.Data; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Identity.Web; using Microsoft.Identity.Web.UI; var builder = WebApplication.CreateBuilder(args); // Add configuration to the container builder.Configuration.AddJsonFile("appsettings.json"); // Adjust the file path as needed // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddCascadingAuthenticationState(); //builder.Services.AddScoped<IdentityUserAccessor>(); builder.Services.AddScoped<IdentityRedirectManager>(); builder.Services.AddScoped<AuthenticationStateProvider, IdentityRevalidatingAuthenticationStateProvider>(); builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, "AzureB2C"); builder.Services.AddControllersWithViews() .AddMicrosoftIdentityUI(); builder.Services.AddRazorPages(); //Configuring appsettings section AzureAdB2C, into IOptions builder.Services.AddOptions(); builder.Services.Configure<OpenIdConnectOptions>(builder.Configuration.GetSection("AzureB2C")); IdentityNoOpEmailSender>(); var app = builder.Build(); // 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.UseAuthentication(); app.UseAuthorization(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents<App>() .AddInteractiveServerRenderMode(); // Add additional endpoints required by the Identity /Account Razor components. app.MapAdditionalIdentityEndpoints(); app.Run();
更新内容
我们创建了一个使用Azure B2C的Blazor Server App,然后按照官方迁移文档将其转换为Blazor Web App,只需确保App.razor和Routes.razor文件位于根目录即可。
内容的提问来源于stack exchange,提问作者Obsidian Delta
相关产品推荐
相关产品推荐

